Skip to content

Commit 90309d5

Browse files
committed
valid parentheses solution
1 parent b06da43 commit 90309d5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

valid-parentheses/devyejin.py

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

0 commit comments

Comments
 (0)