Skip to content

Commit b8eab50

Browse files
authored
Create Valid Parentheses.py
1 parent afb727f commit b8eab50

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

easy/Valid Parentheses.py

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

0 commit comments

Comments
 (0)