Skip to content

Commit e56d2aa

Browse files
committed
添加 problem 268
1 parent 55fd5c0 commit e56d2aa

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package leetcode
2+
3+
func missingNumber(nums []int) int {
4+
xor, i := 0, 0
5+
for i = 0; i < len(nums); i++ {
6+
xor = xor ^ i ^ nums[i]
7+
}
8+
return xor ^ i
9+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package leetcode
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
type question268 struct {
9+
para268
10+
ans268
11+
}
12+
13+
// para 是参数
14+
// one 代表第一个参数
15+
type para268 struct {
16+
s []int
17+
}
18+
19+
// ans 是答案
20+
// one 代表第一个答案
21+
type ans268 struct {
22+
one int
23+
}
24+
25+
func Test_Problem268(t *testing.T) {
26+
27+
qs := []question268{
28+
29+
question268{
30+
para268{[]int{3, 0, 1}},
31+
ans268{2},
32+
},
33+
34+
question268{
35+
para268{[]int{9, 6, 4, 2, 3, 5, 7, 0, 1}},
36+
ans268{8},
37+
},
38+
}
39+
40+
fmt.Printf("------------------------Leetcode Problem 268------------------------\n")
41+
42+
for _, q := range qs {
43+
_, p := q.ans268, q.para268
44+
fmt.Printf("【input】:%v 【output】:%v\n", p, missingNumber(p.s))
45+
}
46+
fmt.Printf("\n\n\n")
47+
}

0 commit comments

Comments
 (0)