Stack1 Valid Parentheses Valid Parentheses 문자열의 유효성 검사하기 Solution class Solution: def isValid(self, s: str) -> bool: stack = [] for c in s: if c in '([{': stack.append(c) elif not stack : return False else: o = stack.pop() if o == '[' and c == ']': continue if o == '(' and c ==')' : continue if o == '{' and c == '}' : continue return False return not stack 2022. 7. 10. 이전 1 다음