classSolution{public:intfindSubstringInWraproundString(stringp){intmaxLength=1;vector<int>count(26);// Substrings end at ifor(inti=0;i<p.length();++i){if(i>0&&(p[i]-p[i-1]==1||p[i-1]-p[i]==25))++maxLength;elsemaxLength=1;constintindex=p[i]-'a';count[index]=max(count[index],maxLength);}returnaccumulate(begin(count),end(count),0);}};
classSolution{publicintfindSubstringInWraproundString(Stringp){intmaxLength=1;int[]count=newint[26];// Substrings end at ifor(inti=0;i<p.length();++i){if(i>0&&(p.charAt(i)-p.charAt(i-1)==1||p.charAt(i-1)-p.charAt(i)==25))++maxLength;elsemaxLength=1;finalintindex=p.charAt(i)-'a';count[index]=Math.max(count[index],maxLength);}returnArrays.stream(count).sum();}}