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
'문제 풀이 > leetcode' 카테고리의 다른 글
Odd Even Linked List (0) | 2022.06.14 |
---|---|
Product of Array (0) | 2022.05.11 |
[leetcode] Group Anagrams (0) | 2022.04.19 |
[leetcode] most common word (0) | 2022.04.19 |
[leetcode] valid palindrome (0) | 2022.02.16 |