Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 7bcf1d4

Browse files
aQuaaQua
aQua
authored and
aQua
committed
736 accepted. 32ms > 3ms
1 parent 3615af3 commit 7bcf1d4

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

Algorithms/0736.parse-lisp-expression/parse-lisp-expression.go

+9-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package Problem0736
22

33
import (
4-
"fmt"
54
"strconv"
65
"strings"
76
)
@@ -35,47 +34,28 @@ func helper(exp string, m map[string]int) int {
3534
for i = 1; i < len(es)-2; i += 2 {
3635
m[es[i]] = helper(es[i+1], copy(m))
3736
}
38-
// TODO: 删除此处内容
39-
fmt.Println("\n=======\n", es[i])
4037
return helper(es[i], copy(m))
4138
}
4239

4340
}
4441

4542
func split(exp string) []string {
46-
// TODO: 删除此处内容
47-
fmt.Println(exp)
4843
ss := strings.Split(exp, " ")
49-
leftCount := 0
44+
countLeft := 0
5045
res := make([]string, 0, len(ss))
5146
for _, s := range ss {
52-
53-
switch s {
54-
case "(":
55-
if leftCount == 0 {
56-
res = append(res, s)
57-
} else {
58-
res[len(res)-1] += " ("
59-
}
60-
leftCount++
61-
case ")":
62-
res[len(res)-1] += " )"
63-
leftCount--
64-
default:
65-
if leftCount == 0 {
66-
res = append(res, s)
67-
} else {
68-
res[len(res)-1] += " " + s
69-
}
47+
if countLeft == 0 {
48+
res = append(res, s)
49+
} else {
50+
res[len(res)-1] += " " + s
7051
}
71-
// TODO: 删除此处内容
72-
fmt.Println(res[len(res)-1])
7352

74-
if s[0] == '(' {
75-
leftCount++
53+
if s == "(" {
54+
countLeft++
7655
} else if s == ")" {
77-
leftCount--
56+
countLeft--
7857
}
58+
7959
}
8060

8161
return res

0 commit comments

Comments
 (0)