-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
476.cpp
32 lines (30 loc) · 821 Bytes
/
476.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
int findComplement(int num) {
int ans=0,i=0;
while(num>0)
{
if(num%2==0)ans=ans|(1<<i);
i++;
num=num/2;
}
return ans;
}
};
__________________________________________________________________________________________________
sample 8772 kb submission
class Solution {
public:
int findComplement(int num) {
int total=0,i=0,numt=num;
while(numt){
total|=(1<<i);
i++;
numt>>=1;
}
return num^total;
}
};
__________________________________________________________________________________________________