프로그래밍/LeetCode
[LeetCode][Python3] 20. Valid Parentheses
snoopybox
2018. 9. 11. 01:50
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 자료구조를 활용한 전형적인 문제