Skip to content

231_PowerofTwo

a920604a edited this page Apr 14, 2023 · 1 revision

title: 231. Power of Two

tags:
- Bit Manipulation categories: leetcode comments: false

solution

class Solution {
public:
    bool isPowerOfTwo(int n) {
        if(n<=0) return false;
        return (n&(n-1)) ==0;
    }
};

analysis

  • time complexity O(1)
  • space complexity O(1)
Clone this wiki locally