We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5773510 commit 0a9d46aCopy full SHA for 0a9d46a
1 file changed
Balanced_Parenthesis
@@ -0,0 +1,31 @@
1
+def arePairs(open,close):
2
+ if open=='[' and close==']':
3
+ return True
4
+ if open=='{' and close=='}':
5
6
+ if open=='(' and close==')':
7
8
+ return False
9
+
10
+def Balanced(A):
11
+ stack=[]
12
+ for i in range(len(A)):
13
+ if A[i]=='[' or A[i]=='{' or A[i]=='(':
14
+ stack.append(A[i])
15
+ elif A[i] == ']' or A[i] == '}' or A[i] == ')':
16
+ if arePairs(stack[-1],A[i] or len(stack)!=0):
17
+ stack.pop()
18
+ else:
19
20
+ if len(stack)==0:
21
22
23
24
25
26
+A="[{())(}]"
27
+print(Balanced(A))
28
29
30
31
0 commit comments