Skip to content

Commit e739a72

Browse files
Create valid_parenthesis.py
1 parent 038b2be commit e739a72

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def isValid(s):
2+
stack = []
3+
closeToOpen = { ")": "(","]" : "[", "}" : "{" }
4+
5+
for c in s:
6+
if c in closeToOpen:
7+
if stack and stack[-1] == closeToOpen[c]:
8+
stack.pop()
9+
else:
10+
return False
11+
else:
12+
stack.append(c)
13+
return True if not stack else False
14+
15+
print(isValid("()[]{}"))

0 commit comments

Comments
 (0)