Python | Leetcode Python题解之第467题环绕字符串中唯一的子字符串
题目:
题解:
class Solution:def findSubstringInWraproundString(self, p: str) -> int:dp = defaultdict(int)k = 0for i, ch in enumerate(p):if i > 0 and (ord(ch) - ord(p[i - 1])) % 26 == 1: # 字符之差为 1 或 -25k += 1else:k = 1dp[ch] = max(dp[ch], k)return sum(dp.values())