一刷 08/2022
Version #1 Divide by 4
Time O(logN)
Space O(1)
Runtime: 1 ms, faster than 100.00% of Java online submissions for Power of Four.
Memory Usage: 41.2 MB, less than 58.81% of Java online submissions for Power of Four.
class Solution {
public boolean isPowerOfFour(int n) {
if (n == 0) {
return false;
}
while (n % 4 == 0) {
n /= 4;
}
return n == 1;
}
}
No comments:
Post a Comment