We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f47f8a6 commit 896a8a6Copy full SHA for 896a8a6
1 file changed
leet code/75 leetcode/20. Valid Parentheses.py
@@ -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
14
15
16
17
+ return True
18
+
19
20
21
+str_data = input('enter the data: ')
22
+print(valid_parathesis(str_data))
0 commit comments