Skip to content

Commit 98b86ca

Browse files
authored
Create 3289. The Two Sneaky Numbers of Digitville (#922)
2 parents e32fefe + 1c69421 commit 98b86ca

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
vector<int> getSneakyNumbers(vector<int>& nums) {
4+
int asum = 0, osum, asqsum = 0, osqsum, n = nums.size() - 2;
5+
if(n < 2){
6+
return {};
7+
}
8+
osum = (n - 1)*(n)/2;
9+
osqsum = (n - 1)*(n)*(2*n - 1)/6;
10+
11+
for(int i = 0 ; i < n + 2; i++){
12+
asum += nums[i];
13+
asqsum += nums[i]*nums[i];
14+
}
15+
16+
int s = asum - osum, q = asqsum - osqsum;
17+
int d = pow((2*q - s*s), 0.5);
18+
int a = (s + d)/2, b = (s - d)/2;
19+
return {b, a};
20+
}
21+
};

0 commit comments

Comments
 (0)