# leetcode20.有效的括号

括号必须对称，括号匹配顺序符合“先进后出”



```golang
func isValid(s string) bool {
    stack:=make([]string,0)

    for _,v:=range s{
        if string(v)=="(" || string(v)=="[" || string(v)=="{"{
            stack=append(stack,string(v))
        }else{
            //不允许先右后左
            if len(stack)==0{
                return false
            }
            pushStack:=stack[len(stack)-1]
            if (pushStack=="(" && string(v)==")") || (pushStack=="[" && string(v)=="]") || (pushStack=="{" && string(v)=="}") {
                stack=stack[:len(stack)-1]
            }else{
                return false
            }
        }
    }

    return len(stack)==0

}
```

