Skip to content

Commit a6dc8d3

Browse files
committed
Add power-of-four.go
1 parent 7c4a43b commit a6dc8d3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

power-of-four.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func isPowerOfFour(num int) bool {
8+
if num <= 0 {
9+
return false
10+
}
11+
for ; num%4 == 0; num /= 4 {
12+
}
13+
return num == 1
14+
}
15+
16+
func main() {
17+
fmt.Println(isPowerOfFour(8))
18+
}

0 commit comments

Comments
 (0)