Skip to content

Commit 038112c

Browse files
authored
Update palindrome-partitioning-iv.py
1 parent b4fd8b3 commit 038112c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Python/palindrome-partitioning-iv.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ def checkPartitioning(self, s):
1010
def modified_manacher(s):
1111
s = '^#' + '#'.join(s) + '#$'
1212
P = [0]*len(s)
13-
dp1 = [False]*len(s) # dp1[i]: s[:i] is a palindromic string
14-
dp2 = [False]*len(s) # dp2[i]: s[:i] is composed of 2 palindromic strings
13+
dp = [0]*len(s) # dp[i]: s[:i] is composed of dp[i] palindromic strings
1514
C, R = 0, 0
1615
for i in xrange(1, len(s)-1):
1716
i_mirror = 2*C-i
1817
if R > i:
1918
P[i] = min(R-i, P[i_mirror])
2019
while s[i+1+P[i]] == s[i-1-P[i]]:
21-
if dp1[i-1-P[i]]:
22-
dp2[(i+1+P[i])+1] = True
20+
if dp[i-1-P[i]]:
21+
dp[(i+1+P[i])+1] = dp[i-1-P[i]]+1
2322
P[i] += 1
24-
if i+1+P[i] == len(s)-1 and dp2[(i-1-P[i])+1]:
23+
if i+1+P[i] == len(s)-1 and dp[(i-1-P[i])+1] == 2:
2524
return True
2625
if i-1-P[i] == 0:
27-
dp1[i+1+P[i]] = True
26+
dp[i+1+P[i]] = 1
2827
if i+P[i] > R:
2928
C, R = i, i+P[i]
3029
return False

0 commit comments

Comments
 (0)