Skip to content

Commit

Permalink
移除最外括号
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Apr 13, 2019
1 parent 0dc8d96 commit 599262e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 1021. Remove Outermost Parentheses/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main
import "fmt"

func removeOuterParentheses(S string) string {
res := make([]rune, 0, len(S))
flag := 0
for _, ch := range S{
if ch == '(' {
if flag != 0 {
res = append(res, ch)
}
flag++
} else {
flag--
if flag != 0 {
res = append(res,ch)
}
}
}
return string(res)
}

func main(){
S := "()()"
res := removeOuterParentheses(S)
fmt.Println("res:", res, ".")
}

0 comments on commit 599262e

Please sign in to comment.