Skip to content

Commit 5023e40

Browse files
committed
[feat] 2025-2-25 daily test
1 parent c2995e3 commit 5023e40

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
15
class Solution {
26
public:
37
int singleNumber(vector<int>& nums) {
@@ -18,24 +22,30 @@ class Solution {
1822
public:
1923
int singleNumber(vector<int>& nums) {
2024
vector<int> array(32);
25+
array.assign(array.size(), 0);
2126
int ret = 0;
22-
for(int i = 0; i < nums.size(); i++)
23-
{
24-
for(int j = 0; j < 32; j++)
25-
{
26-
if(nums[i] & (1 << j))
27-
{
28-
array[j]++;
29-
}
30-
}
31-
}
3227
for(int i = 0; i < 32; i++)
3328
{
34-
if(array[i] % 3)
29+
for(int j = 0; j < nums.size(); j++)
3530
{
36-
ret += ((array[i] % 3) << i);
31+
array[i] += (nums[j] >> i) & 1;
3732
}
33+
array[i] %= 3;
34+
ret |= array[i] << i;
3835
}
3936
return ret;
4037
}
41-
};
38+
};
39+
40+
int main()
41+
{
42+
Solution solution;
43+
int a[4] = {2,2,3,2};
44+
vector<int> b;
45+
b.insert(b.begin(),a,a+4);
46+
int result = solution.singleNumber(b);
47+
cout << "Result of Solution is: " << result << endl;
48+
49+
return 0;
50+
}
51+
Binary file not shown.

0 commit comments

Comments
 (0)