Leetcode (go语言) 4的幂次方

package main

import (
    "fmt"
    "strconv"
)

func isPowerOfFour(num int) bool {
    if num < 0 || (num & (num-1)) != 0 {
        return false
    }

    n, err := strconv.ParseInt("55555555", 16 ,32)
    if err != nil {
        panic(err)
    }

    n2 := int(n)
    return num & n2 > 0
}


func main() {
    fmt.Println(isPowerOfFour(16))

}
image.png

你可能感兴趣的:(Leetcode (go语言) 4的幂次方)