关于符号对应那里,之前有点想法,思考了下,才有思路
func isValid(s string) bool {
length := len(s)
if length % 2 != 0{
return false
}
result := make([]byte, length)
paris := map[byte]byte{
')': '(',
']':'[',
'}': '{',
}
j:=0
for i :=0;i<length;i++{
if s[i] == '(' || s[i] == '{' || s[i] == '['{
result[j] = s[i]
j++
}else{
if j==0{
return false
}
if paris[s[i]] != result[j-1]{
return false
}
j--
}
}
if j == 0{
return true
}
return false
}