-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid Parentheses.py
More file actions
32 lines (29 loc) · 819 Bytes
/
Copy pathValid Parentheses.py
File metadata and controls
32 lines (29 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__author__ = 'Martin'
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack = []
for i in s:
if len(stack) != 0:
if i == ')' and stack[len(stack)-1] == '(':
stack.pop()
continue
elif i == ']' and stack[len(stack)-1] == '[':
stack.pop()
continue
elif i == '}' and stack[len(stack)-1] == '{':
stack.pop()
continue
else:
stack.append(i)
else:
stack.append(i)
if len(stack) != 0:
return False
else:
return True
s = Solution()
print(s.isValid("{[()]}"))