1 2 3 4 5 6 7 8 9 10 11
| class Solution { public: int findSubstringInWraproundString(string p) { int f[26] = {0}, cnt = 0; for (int i = 0; i < p.size(); ++i) { cnt = i && (p[i] - p[i - 1] + 26) % 26 == 1 ? cnt + 1 : 1; f[p[i] - 'a'] = max(f[p[i] - 'a'], cnt); } return accumulate(f, f + 26, 0); } };
|