# 0869. Reordered Power of 2 ###### tags: `Leetcode` `Medium` `Bit Manipulation` `HashMap` Link: https://leetcode.com/problems/reordered-power-of-2/description/ ## 思路 用一个long数字就可以记录一个int数字里面每一个digit有几个 因为一个n最大是10^9 所以一个digit最多重复9次 如果n有可能大于10^9 那么可以用map记录 ## Code ```java= class Solution { public boolean reorderedPowerOf2(int n) { long c = counter(n); for(int i=0; i<32; i++){ if(counter(1<<i)==c) return true; } return false; } public long counter(int n){ int count = 0; while(n!=0){ count += Math.pow(10, n%10); n/=10; } return count; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up