Skip to content

Commit 221a6d5

Browse files
authored
add: single-number-ii solution in go (#46)
1 parent 402c420 commit 221a6d5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ LeetCode
140140
|0134|[Gas Station](https://leetcode.com/problems/gas-station/) || [c++](./src/0134-Gas-Station/0134.cpp) |[python](./src/0134-Gas-Station/0134.py)|||||Medium|
141141
|0135|[Candy](https://leetcode.com/problems/gas-station/) || [c++](./src/0134-Gas-Station/0134.cpp) |[python](./src/0134-Gas-Station/0134.py)|||||Hard|
142142
|0136|[Single Number](https://leetcode.com/problems/single-number/) || [c++](./src/0136-Single-Number/0136.cpp) |[python](./src/0136-Single-Number/0136.py)|[go](./src/0136-Single-Number/0136.go)||||Easy|
143-
|0137|[Single Number II](https://leetcode.com/problems/single-number-ii/) || [c++](./src/0137-Single-Number-II/0137.cpp) |[python](./src/0137-Single-Number-II/0137.py)|||||Medium|
143+
|0137|[Single Number II](https://leetcode.com/problems/single-number-ii/) || [c++](./src/0137-Single-Number-II/0137.cpp) |[python](./src/0137-Single-Number-II/0137.py)|[go](./src/0137-Single-Number-II/0137.go)||||Medium|
144144
|0138|[Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/) || [c++](./src/0138-Copy-List-with-Random-Pointer/0138.cpp) |[python](./src/0138-Copy-List-with-Random-Pointer/0138.py)|||||Medium|
145145
|0139|[Word Break](https://leetcode.com/problems/word-break/) || [c++](./src/0139-Word-Break/0139.cpp) |[python](./src/0139-Word-Break/0139.py)|||||Medium|
146146
|0140|[Word Break II](https://leetcode.com/problems/word-break-ii/) || [c++](./src/0140-Word-Break-II/0140.cpp) |[python](./src/0140-Word-Break-II/0140.py)|||||Hard|

src/0137-Single-Number-II/0137.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package singlenumberii
2+
3+
func singleNumber(nums []int) int {
4+
ans := 0
5+
for bit := 1; bit != 0; bit <<= 1 {
6+
count := 0
7+
for _, num := range nums {
8+
if num&bit != 0 {
9+
count++
10+
}
11+
}
12+
if count%3 == 1 {
13+
ans |= bit
14+
}
15+
}
16+
return ans
17+
}

0 commit comments

Comments
 (0)