Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 451 Bytes

Question_231.md

File metadata and controls

23 lines (19 loc) · 451 Bytes

LeetCode Records - Question 231 Power of Two

Attempt 1: Remove all the trailing zeros first

class Solution {
    public boolean isPowerOfTwo(int n) {
        if (n <= 0) {
            return false;
        }

        int i = 0;
        for (; i < 31 && (n & 0x1) == 0; i++) {
            n >>= 1;
        }

        return n == 1;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 40.51 MB (Beats: 78.98%)