Skip to content

Commit 9c76a62

Browse files
committed
[:solved] #222
1 parent 6d1146a commit 9c76a62

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-parentheses/ppxyn1.py

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

0 commit comments

Comments
 (0)