class Solution {
public boolean reorderedPowerOf2(int n) {
int[] frequency1 = new int[10];
int[] frequency2 = new int[10];
String num = ""+n;
for (int i = 0; i < num.length(); i++) {
int index = num.charAt(i) - '0';
frequency1[index]++;
}
for (int i = 0; i < 32; i++) {
String t = (1 << i) + "";
if (num.length() == t.length()) {
for (int j = 0; j < num.length(); j++) {
int index = t.charAt(j) - '0';
frequency2[index]++;
}
boolean ans = true;
for (int j = 0; j < 10; j++) {
if (frequency1[j] != frequency2[j]) {
ans = false;
break;
}
}
if (ans) {
return true;
}
for (int j = 0; j < 10; j++) {
frequency2[j] = 0;
}
}
}
return false;
}
}
0数学中等 LeetCode869. 重新排序得到 2 的幂
最新推荐文章于 2024-09-08 15:12:17 发布