Skip to content

Commit daf65db

Browse files
authored
Create validParentheses.py
1 parent c8d597e commit daf65db

File tree

1 file changed

+17
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)