-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
39 lines (36 loc) · 951 Bytes
/
main.py
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
# Author : Qi Zhang
# Date : 2018-12-11
# 此处可 import 模块
"""
@param string line 为单行测试数据
@return string 处理后的结果
"""
def solution(line):
s = line.rstrip()
st = []
ans = True
for c in s:
if c == '[' or c == '(' or c == '{':
st.append(c)
else:
if c == ']':
if len(st) > 0 and st[-1] == '[':
st.pop(-1)
else:
ans = False
break
if c == ')':
if len(st) > 0 and st[-1] == '(':
st.pop(-1)
else:
ans = False
break
if c == '}':
if len(st) > 0 and st[-1] == '{':
st.pop(-1)
else:
ans = False
break
if len(st) > 0:
ans = False
return "1" if ans else "0"