Skip to content

Latest commit

 

History

History
16 lines (10 loc) · 276 Bytes

231-Power-of-Two.md

File metadata and controls

16 lines (10 loc) · 276 Bytes

231. Power of Two

Given an integer, write a function to determine if it is a power of two.

Solution

class Solution {
    func isPowerOfTwo(_ n: Int) -> Bool {
         return n > 0 ? (n == 1 ? true : (n % 2 == 0) && isPowerOfTwo(n / 2)) : false
    }
}