-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathExample01.py
More file actions
45 lines (37 loc) · 999 Bytes
/
Example01.py
File metadata and controls
45 lines (37 loc) · 999 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
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
class Solution:
def isValid(self, s):
if not s or len(s) == 0:
return True
if len(s) % 2 == 1:
return False
t = []
for c in s:
if c == '(':
t.append(c)
elif c == ')':
if len(t) == 0:
return False
t.pop()
else:
return False
return len(t) == 0
solution = Solution()
assert solution.isValid("")
assert not solution.isValid("(")
assert not solution.isValid(")")
assert solution.isValid("()")
assert not solution.isValid("((")
assert not solution.isValid("))")
assert not solution.isValid(")(")
assert not solution.isValid("())")
assert not solution.isValid("(((")
assert not solution.isValid(")))")
assert not solution.isValid(")()")
assert solution.isValid("()()")
assert solution.isValid("(())")
assert not solution.isValid("))((")
assert solution.isValid("()()()")
assert solution.isValid("((()))")
assert solution.isValid("()(())")
assert not solution.isValid("()(()(")