class Solution:
def isValid(self, s: str) -> bool:
charDict = {')':'(', '}':'{', ']':'['}
stack = []
for w in s:
if w in charDict and stack:
if stack[-1] != charDict[w]:
return False
else:
stack.pop()
else:
stack.append(w)
# 여기까지 오고, stack 이 비어있지 않으면 False
return True if not stack else False'LeetCode > Grind169' 카테고리의 다른 글
| 121. Best Time to Buy and Sell Stock ☆ (0) | 2025.04.22 |
|---|---|
| 21. Merge Two Sorted Lists ☆ (0) | 2025.04.22 |
| 1. Two Sum (0) | 2025.04.22 |
| [LinkedLists: Fast and Slow Pointers] 287. Find the Duplicate Number ★★★★★ (1) | 2025.04.06 |
| [Prefix Sums] 560. Subarray Sum Equals K ★★★★★ (0) | 2025.04.05 |