Skip to content

Commit 01a553b

Browse files
committed
valid-parentheses solution
1 parent 7811238 commit 01a553b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

valid-parentheses/sungjinwi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def isValid(self, s: str) -> bool:
3+
stack = []
4+
pair = dict(zip('({[',')}]'))
5+
for paren in s :
6+
if paren in pair :
7+
stack.append(paren)
8+
elif not stack :
9+
return False
10+
elif pair[stack[-1]] == paren :
11+
stack.pop()
12+
else:
13+
return False
14+
if not stack :
15+
return True
16+
else :
17+
return False

0 commit comments

Comments
 (0)