0467.cpp (495B)
1 class Solution { 2 public: 3 int findSubstringInWraproundString(const string &s) const { 4 const int n = size(s); 5 static int seen[26]; 6 7 memset(seen, 0x00, sizeof(seen)); 8 for (const char c : s) 9 seen[c - 'a'] = 1; 10 for (int i = 1, cnt = 1; i < n; i++) { 11 cnt = (s[i] - s[i - 1] + 26) % 26 == 1 ? cnt + 1 : 1; 12 seen[s[i] - 'a'] = max(seen[s[i] - 'a'], cnt); 13 } 14 15 return accumulate(seen, seen + 26, 0); 16 } 17 };