8000 添加 problem 781 · DontFearAlgorithms/LeetCode-Go@e5cb491 · GitHub
[go: up one dir, main page]

Skip to content

Commit e5cb491

Browse files
committed
添加 problem 781
1 parent e183435 commit e5cb491

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package leetcode
2+
3+
func numRabbits(ans []int) int {
4+
total, m := 0, make(map[int]int)
5+
for _, v := range ans {
6+
if m[v] == 0 {
7+
m[v] += v
8+
total += v + 1
9+
} else {
10+
m[v]--
11+
}
12+
}
13+
return total
14+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package leetcode
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
type question781 struct {
9+
para781
10+
ans781
11+
}
12+
13+
// para 是参数
14+
// one 代表第一个参数
15+
type para781 struct {
16+
one []int
17+
}
18+
19+
// ans 是答案
20+
// one 代表第一个答案
21+
type ans781 struct {
22+
one int
23+
}
24+
25+
func Test_Problem781(t *testing.T) {
26+
27+
qs := []question781{
28+
question781{
29+
para781{[]int{1, 1, 2}},
30+
ans781{5},
31+
},
32+
33+
question781{
34+
para781{[]int{10, 10, 10}},
35+
ans781{11},
36+
},
37+
38+
question781{
39+
para781{[]int{}},
40+
ans781{0},
41+
},
42+
}
43+
44+
fmt.Printf("------------------------Leetcode Problem 781------------------------\n")
45+
46+
for _, q := range qs {
47+
_, p := q.ans781, q.para781
48 4601 +
fmt.Printf("【input】:%v 【output】:%v\n", p, numRabbits(p.one))
49+
}
50+
fmt.Printf("\n\n\n")
51+
}

0 commit comments

Comments
 (0)
0