File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -20,13 +20,13 @@ def find_minimum_partitions(string: str) -> int:
20
20
>>> find_minimum_partitions("ababbbabbababa")
21
21
3
22
22
"""
23
- n = len (string )
24
- cut = [0 ] * n
25
- is_palindromic = [[False for i in range (n )] for j in range (n )]
26
- for i in range ( n ):
23
+ length = len (string )
24
+ cut = [0 ] * length
25
+ is_palindromic = [[False for i in range (length )] for j in range (length )]
26
+ for i , c in enumerate ( length ):
27
27
mincut = i
28
28
for j in range (i + 1 ):
29
- if string [ i ] == string [j ] and (i - j < 2 or ispalindrome [j + 1 ][i - 1 ]):
29
+ if c == string [j ] and (i - j < 2 or ispalindrome [j + 1 ][i - 1 ]):
30
30
is_palindromic [j ][i ] = True
31
31
mincut = min (mincut , 0 if j == 0 else (cut [j - 1 ] + 1 ))
32
32
cut [i ] = mincut
@@ -36,4 +36,4 @@ def find_minimum_partitions(string: str) -> int:
36
36
if __name__ == "__main__" :
37
37
s = input ("Enter the string: " ).strip ()
38
38
ans = find_minimum_partitions (s )
39
- print (f"Minimum number of partitions required for the string is { ans } " )
39
+ print (f"Minimum number of partitions required for the ' { s } ' is { ans } " )
You can’t perform that action at this time.
0 commit comments