20. Valid Parentheses
Easy
Problem:
Input: s = "()[]{}"
Output: trueSolution:
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) == 0Last updated