class Solution:
def isValid(self, s: str) -> bool:
stack = []
table = {
")":"(",
"]":"[",
"}":"{"
}
for char in s:
if char not in table:
stack.append(char)
elif not stack or table[char] != stack.pop():
return False
return len(stack) == 0
'자료구조와 알고리즘' 카테고리의 다른 글
739. Daily Temperatures(일일 온도) (0) | 2023.02.13 |
---|---|
316. Remove Duplicate Letters(중복 문자 제거) (0) | 2023.02.13 |
2. Add Two Numbers(두 수의 덧셈) (0) | 2023.02.08 |
206. Reversed Linked List(역순 연결 리스트) (0) | 2023.02.08 |
21. Merge Two Sorted Lists(두 정렬 리스트의 병합) (0) | 2023.02.06 |