一刷
Version #1 Bit Manipulation
Time O(1)
Runtime: 2 ms, faster than 60.97% of Java online submissions for Power of Two.
Memory Usage: 41.5 MB, less than 40.22% of Java online submissions for Power of Two.
class Solution {
public boolean isPowerOfTwo(int n) {
return n > 0 && (n & (n - 1)) == 0;
}
}
No comments:
Post a Comment