Skip to content

Commit 896a8a6

Browse files
committed
20. Valid Parentheses
1 parent f47f8a6 commit 896a8a6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 20. Valid Parentheses
2+
def valid_parathesis(s):
3+
stacks = list()
4+
data = {'(':')','{':'}','[':']'}
5+
for i in s:
6+
if i not in data:
7+
stacks.append(i)
8+
else:
9+
if not stacks:
10+
return False
11+
elif data[stacks[-1]]==i:
12+
stacks.pop()
13+
else:
14+
return False
15+
if not stacks:
16+
return False
17+
return True
18+
19+
20+
21+
str_data = input('enter the data: ')
22+
print(valid_parathesis(str_data))

0 commit comments

Comments
 (0)