Swift solution


  • 0
    class Solution {
        func isPowerOfTwo(_ n: Int) -> Bool {
            if n <= 0 {
                return false
            }
            
            return (n & (n - 1)) == 0
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.