-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path869.cpp
41 lines (38 loc) · 1.1 KB
/
869.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
33
34
35
36
37
38
39
40
41
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
bool reorderedPowerOf2(int N) {
int ntrans = helper(N);
for(int i=0;i<32;++i){
if(ntrans == helper(1<<i)) return true;
}
return false;
}
int helper(int N){
int res = 0;
while(N){
res+=pow(10, N%10);
N /=10;
}
return res;
}
};
__________________________________________________________________________________________________
sample 8812 kb submission
class Solution {
public:
bool reorderedPowerOf2(int N) {
string strN = to_string(N);
sort(strN.begin(), strN.end());
for (int i = 0; i < 31; i++) {
string pow2i = to_string(1 << i);
sort(pow2i.begin(), pow2i.end());
if (strN == pow2i) {
return true;
}
}
return false;
}
};
__________________________________________________________________________________________________