File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 3
3
of opening and closing backets i.e. '(', ')', '[', ']'
4
4
'?' can be used to replace as any of the bracket.
5
5
'''
6
-
7
- form collections import Copy
6
+ from collections import Counter
8
7
from copy import copy
9
8
10
9
def check (count ):
@@ -16,22 +15,24 @@ def check(count):
16
15
count ['(' ] = max (count ['(' ] , count [')' ])
17
16
count [')' ] = max (count ['(' ] , count [')' ])
18
17
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 )
25
24
26
25
27
26
def fillMissingBrackets (s ):
28
27
left_count = Counter ()
29
28
right_count = Counter (s )
30
29
ret = 0
30
+
31
31
for i in s [:- 1 ]:
32
32
left_count [i ] += 1
33
- right_count [i ] 1 = 1
33
+ right_count [i ] + = 1
34
34
if check (copy (left_count )) and check (copy (right_count )):
35
- ret += 1
36
- return ret
35
+ ret += 1
36
+
37
+ return ret
37
38
You can’t perform that action at this time.
0 commit comments