Skip to content

Commit f38a0e4

Browse files
committed
update
1 parent 519551a commit f38a0e4

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

others/BalancedSubstrings.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
of opening and closing backets i.e. '(', ')', '[', ']'
44
'?' can be used to replace as any of the bracket.
55
'''
6-
7-
form collections import Copy
6+
from collections import Counter
87
from copy import copy
98

109
def check(count):
@@ -16,22 +15,24 @@ def check(count):
1615
count['('] = max(count['('] , count[')'])
1716
count[')'] = max(count['('] , count[')'])
1817

19-
if not(squar) and count['?'] >= abs(count['['] - count[']']):
20-
count['?'] -= abs(count['['] - count[']'])
21-
count['('] = max(count['['] , count[']'])
22-
count[')'] = max(count['['] , count[']'])
23-
24-
return (count['('] == count[')']) and (count['['] == count[']']) and (count['?']%2 == 0)
18+
if not(squar) and count['?'] >= abs(count['['] - count[']']):
19+
count['?'] -= abs(count['['] - count[']'])
20+
count['('] = max(count['['] , count[']'])
21+
count[')'] = max(count['['] , count[']'])
22+
23+
return (count['('] == count[')']) and (count['['] == count[']']) and (count['?']%2 == 0)
2524

2625

2726
def fillMissingBrackets(s):
2827
left_count = Counter()
2928
right_count = Counter(s)
3029
ret = 0
30+
3131
for i in s[:-1]:
3232
left_count[i] += 1
33-
right_count[i] 1= 1
33+
right_count[i] += 1
3434
if check(copy(left_count)) and check(copy(right_count)):
35-
ret += 1
36-
return ret
35+
ret += 1
36+
37+
return ret
3738

0 commit comments

Comments
 (0)