Skip to content

Commit ef0b020

Browse files
authored
feat: 342. Power of Four (#101)
Signed-off-by: ashing <[email protected]>
1 parent 76639ff commit ef0b020

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

leetcode/0342/342. Power of Four.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package _342
2+
3+
func isPowerOfFour(n int) bool {
4+
return n > 0 && n&(n-1) == 0 && n&0xaaaaaaaa == 0
5+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package _342
2+
3+
import "testing"
4+
5+
func Test_isPowerOfFour(t *testing.T) {
6+
type args struct {
7+
n int
8+
}
9+
tests := []struct {
10+
name string
11+
args args
12+
want bool
13+
}{
14+
{
15+
name: "one",
16+
args: args{
17+
n: 16,
18+
},
19+
want: true,
20+
},
21+
}
22+
for _, tt := range tests {
23+
t.Run(tt.name, func(t *testing.T) {
24+
if got := isPowerOfFour(tt.args.n); got != tt.want {
25+
t.Errorf("isPowerOfFour() = %v, want %v", got, tt.want)
26+
}
27+
})
28+
}
29+
}

0 commit comments

Comments
 (0)