Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0e87ace

Browse files
committedMay 3, 2025
Solve : Valid Parentheses
1 parent 8d49797 commit 0e87ace

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)
Please sign in to comment.