把字符串 s 看作是 “abcdefghijklmnopqrstuvwxyz” 的无限环绕字符串,所以 s 看起来是这样的:
"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd...." .
现在给定另一个字符串 p 。返回 s 中 唯一 的 p 的 非空子串 的数量 。
class Solution {
public int findSubstringInWraproundString(String p) {
int[] temp = new int[26];
int k = 0;
for(int i = 0;i < p.length();i++){
if(i >= 1 && (p.charAt(i) - p.charAt(i-1)+26)%26 == 1){
++k;
}else{
k = 1;
}
temp[p.charAt(i) - 'a'] = Math.max(k,temp[p.charAt(i));
}
return Arrays.stream(temp).sum();
}
}



