Back to course home
0% completed
Vote For New Content
The simplest solution
Andrew Sologor
Apr 10, 2025
func isValid(s1 string) bool { stack := []rune{} for _, c := range s1 { switch c { case '(': stack = append(stack, ')') case '[': stack = append(stack, ']') case '{': stack = append(stack, '}') case ')', ']', '}': if len(stack) == 0 || stack[len(stack) - 1] != c { return false } // remove the last element from the stack stack = stack[:len(stack) - 1] } } return len(stack) == 0 }
0
0
Comments
Comments
On this page