Skip to content

Commit 86af7e8

Browse files
Added bubble sort implementation in Python
1 parent e2a78d4 commit 86af7e8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

algorithms/valid-parentheses.py

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

0 commit comments

Comments
 (0)