Problem :

https://leetcode.com/problems/valid-parentheses/description/


My Solution :

class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
pairs = {'(': ')', '{': '}', '[': ']'}
stack = []
for c in s:
if c in pairs:
stack.append(c)
elif not stack or c != pairs[stack.pop()]:
return False
if stack:
return False
return True


Comment :

Stack 자료구조를 활용한 전형적인 문제