forked from piyush01123/Daily-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsol.py
31 lines (27 loc) · 690 Bytes
/
sol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def balancedBrackes(S: str) -> bool:
ctr_rnd = 0
ctr_crly = 0
ctr_sqr = 0
for char in S:
if char=='(':
ctr_rnd+=1
elif char=='{':
ctr_crly+=1
elif char=='[':
ctr_sqr+=1
elif char==')':
ctr_rnd-=1
elif char=='}':
ctr_crly-=1
elif char==']':
ctr_sqr-=1
if ctr_rnd<0 or ctr_crly<0 or ctr_sqr<0:
return False
if ctr_rnd==ctr_crly==ctr_sqr==0:
return True
else:
return False
if __name__=='__main__':
print(balancedBrackes("([])[]({})"))
print(balancedBrackes("([)]"))
print(balancedBrackes("((()"))