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