Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit038112c

Browse files
authored
Update palindrome-partitioning-iv.py
1 parentb4fd8b3 commit038112c

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
defmodified_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
foriinxrange(1,len(s)-1):
1716
i_mirror=2*C-i
1817
ifR>i:
1918
P[i]=min(R-i,P[i_mirror])
2019
whiles[i+1+P[i]]==s[i-1-P[i]]:
21-
ifdp1[i-1-P[i]]:
22-
dp2[(i+1+P[i])+1]=True
20+
ifdp[i-1-P[i]]:
21+
dp[(i+1+P[i])+1]=dp[i-1-P[i]]+1
2322
P[i]+=1
24-
ifi+1+P[i]==len(s)-1anddp2[(i-1-P[i])+1]:
23+
ifi+1+P[i]==len(s)-1anddp[(i-1-P[i])+1]==2:
2524
returnTrue
2625
ifi-1-P[i]==0:
27-
dp1[i+1+P[i]]=True
26+
dp[i+1+P[i]]=1
2827
ifi+P[i]>R:
2928
C,R=i,i+P[i]
3029
returnFalse

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp