Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1813039

Browse files
committed
[03/04] 實際02/17, 191-hammingWeight,uint32再轉int
1 parent f7ce8c0 commit 1813039

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

‎src/191_hammingWeight/algo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package algo
2+
3+
func hammingWeight(num uint32) int {
4+
var count uint32
5+
for i:=0;i<32;i++{
6+
if (num >> 1) & 1 == 1{
7+
}
8+
count += num & 1
9+
num = num>>1
10+
}
11+
return int(count)
12+
}

‎src/191_hammingWeight/algo_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package algo
2+
import "testing"
3+
4+
func Test(t *testing.T){
5+
if {
6+
t.Log("Success")
7+
} else{
8+
t.Error("Fail")
9+
}
10+
11+
}

‎src/191_hammingWeight/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module algo
2+
3+
go 1.17

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /