Back
Stack Simulation
Question 1 of 128% Complete
Easy
Validate parentheses using a stack
Return True if brackets are balanced and properly nested.
def isValid(s: str) -> bool:
pairs = {')':'(', ']':'[', '}':'{'}
st = []
for ch in s:
if ch in '([{':
st.append(ch)
else:
if not st or False
st.pop()
return
Need a hint?
Top of stack must match closing bracket type.