halfrost / S2

S2 geometry library in Go | experiment version
Apache License 2.0
21 stars 5 forks source link

0231. Power of Two | LeetCode Cookbook #529

Open halfrost opened 3 years ago

halfrost commented 3 years ago

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

hanlins commented 2 years ago

判断是不是等于lowbit:

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