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 bec16ff commit 791f6e7Copy full SHA for 791f6e7
Stack/P02_BalancedParenthesis.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('((()))'))
27
+ print(parseParenthesis('((())'))
0 commit comments