Skip to content

Commit 8b7c889

Browse files
author
hero
committed
棒球比赛
1 parent 150113a commit 8b7c889

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

leet_code/calPoints_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package leet_code
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
)
7+
8+
//棒球比赛
9+
func calPoints(ops []string) int {
10+
array := make([]int, 0, len(ops))
11+
for _, v := range ops {
12+
switch v {
13+
case "+":
14+
array = append(array, array[len(array)-1]+array[len(array)-2])
15+
case "D":
16+
array = append(array, array[len(array)-1]*2)
17+
case "C":
18+
array = array[:len(array)-1]
19+
default:
20+
i, _ := strconv.Atoi(v)
21+
array = append(array, i)
22+
}
23+
}
24+
var num int
25+
for _, v := range array {
26+
num += v
27+
}
28+
return num
29+
}
30+
31+
func Test_calPoints(t *testing.T) {
32+
ps := []string{"5", "2", "C", "D", "+"}
33+
t.Log(calPoints(ps))
34+
}

leet_code/waysToStep_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
)
66

7+
//三步问题
78
func waysToStep(n int) int {
89
var d = make([]int, n+4)
910
d[0] = 0

0 commit comments

Comments
 (0)