题目:

解析:

代码:
public int findSubstringInWraproundString(String ss) {
int n = ss.length();
int[] dp = new int[n];
char[] s = ss.toCharArray();
for(int i = 0; i < n; i++) dp[i] = 1;
for(int i = 1; i < n; i++){
if(s[i - 1] + 1 == s[i] || (s[i - 1] == 'z' && s[i] == 'a'))
dp[i] += dp[i-1];
}
//去重:把dp表中的字串重复的,只留最长的字串(hash表来建立映射关系)
int[] hash = new int[26];
for(int i = 0; i < n; i++)
hash[s[i]-'a'] = Math.max(hash[s[i]-'a'], dp[i]);
//返回
int ret = 0;
for(int x : hash)
ret += x;
return ret;
}