Skip to content

Commit f423e88

Browse files
committed
adding valid parentheses
1 parent 1c3a16b commit f423e88

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-parentheses/daiyongg-kim.py

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

0 commit comments

Comments
 (0)