-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path470.implement-rand10-using-rand7.java
More file actions
46 lines (35 loc) · 998 Bytes
/
Copy path470.implement-rand10-using-rand7.java
File metadata and controls
46 lines (35 loc) · 998 Bytes
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
42
43
44
45
46
class Solution {
public boolean reorderedPowerOf2(int N) {
int[][] mapr = new int[31][10];
int p = 0;
// System.out.println((1<<4));
while(p<31){
int val = (1<<p);
// System.out.println(val+" "+p);
while(val != 0){
mapr[p][val%10]++;
val= val/10;
}
p++;
}
p = 0;
while(p<31){
int val = N;
while(val != 0){
if(mapr[p][val%10] > 0)
mapr[p][val%10]--;
else
break;
val= val/10;
}
int check = p;
int k= 0;
while(k<10 && mapr[check][k] == 0)
k++;
if(k == 10 && val == 0)
return true;
p++;
}
return false;
}
}