We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce3e91a commit 2af624fCopy full SHA for 2af624f
data_structures/Stacks/Balanced_Parentheses.py
@@ -0,0 +1,27 @@
1
+# Author: OMKAR PATHAK
2
+
3
+import Stack
4
5
+def parseParenthesis(string):
6
+ balanced = 1
7
+ index = 0
8
+ myStack = Stack.Stack(len(string))
9
+ while (index < len(string)) and (balanced == 1):
10
+ check = string[index]
11
+ if check == '(':
12
+ myStack.push(check)
13
+ else:
14
+ if myStack.isEmpty():
15
+ balanced = 0
16
17
+ myStack.pop()
18
+ index += 1
19
20
+ if balanced == 1 and myStack.isEmpty():
21
+ return True
22
23
+ return False
24
25
+if __name__ == '__main__':
26
+ print(parseParenthesis('((()))')) # True
27
+ print(parseParenthesis('((())')) # False
0 commit comments