链接:https://leetcode-cn.com/problems/reordered-power-of-2/
枚举所有2的幂,获得它们的数字组合,并与输入的数字组合相比较。
java代码:
class Solution {
public boolean reorderedPowerOf2(int N) {
int []Ncount = count(N);
for(int i = 0;i<31;i++)
{
if(Arrays.equals(Ncount,count(1<<i)))
return true;
}
return false;
}
private int [] count(int N)
{
int [] res = new int [10];
while(N>0)
{
res[N%10]++;
N/=10;
}
return res;
}
}