From 758efeee37b98df3ae262fab258530a35269bd4a Mon Sep 17 00:00:00 2001 From: ashing Date: Sun, 25 Feb 2024 22:46:41 +0800 Subject: [PATCH] feat: 342. Power of Four Signed-off-by: ashing --- leetcode/0342/342. Power of Four.go | 5 ++++ leetcode/0342/342. Power of Four_test.go | 29 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 leetcode/0342/342. Power of Four.go create mode 100644 leetcode/0342/342. Power of Four_test.go diff --git a/leetcode/0342/342. Power of Four.go b/leetcode/0342/342. Power of Four.go new file mode 100644 index 0000000..6b3e8f5 --- /dev/null +++ b/leetcode/0342/342. Power of Four.go @@ -0,0 +1,5 @@ +package _342 + +func isPowerOfFour(n int) bool { + return n > 0 && n&(n-1) == 0 && n&0xaaaaaaaa == 0 +} diff --git a/leetcode/0342/342. Power of Four_test.go b/leetcode/0342/342. Power of Four_test.go new file mode 100644 index 0000000..f83b548 --- /dev/null +++ b/leetcode/0342/342. Power of Four_test.go @@ -0,0 +1,29 @@ +package _342 + +import "testing" + +func Test_isPowerOfFour(t *testing.T) { + type args struct { + n int + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "one", + args: args{ + n: 16, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := isPowerOfFour(tt.args.n); got != tt.want { + t.Errorf("isPowerOfFour() = %v, want %v", got, tt.want) + } + }) + } +}