S2 icon indicating copy to clipboard operation
S2 copied to clipboard

0231. Power of Two | LeetCode Cookbook

Open halfrost opened this issue 4 years ago • 1 comments

https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0231.Power-of-Two/

halfrost avatar Feb 26 '21 13:02 halfrost

判断是不是等于lowbit:

func isPowerOfTwo(n int) bool {
    if n <= 0 {
        return false
    }
    lowbit := n & (-n)
    return lowbit == n
}

hanlins avatar Mar 15 '22 07:03 hanlins