forked from Mickey0521/Codility-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNesting.py
More file actions
27 lines (19 loc) · 655 Bytes
/
Nesting.py
File metadata and controls
27 lines (19 loc) · 655 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
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(S):
# write your code in Python 3.6
my_stack = []
for char in S:
if char == '(':
my_stack.append(char)
elif char == ')':
# note: check if the stack is empty or not (be careful)
if len(my_stack) == 0:
return 0
else:
pop = my_stack.pop( len(my_stack)-1 )
# note: check if the stack is empty or not (be careful)
if len(my_stack) != 0:
return 0
else:
return 1