R4-字符串
动态规划
class Solution:
def findSubstringInWraproundString(self, s: str) -> int:
dp=[0]*26
num=1
#dp初始化
dp[ord(s[0])-ord('a')]=1
for c1,c2 in pairwise(s):
if not (ord(c2)-ord(c1)-1)%26:
num+=1
else:
num=1
dp[id]=max(dp[id := ord(c2)-ord('a')],num)
return sum(dp)
ps:
ord()计算ASCII值
#连取两个
for c1, c2 in pairwise(p):