467. 环绕字符串中唯一的子字符串

467. 环绕字符串中唯一的子字符串

题解

class Solution {
 public:
  int findSubstringInWraproundString(string p) {
    int n = p.size();
    vector cnt(26, 0);
    int res = 0;
    int len = 1;
    cnt[p[0] - 'a']++;
    for (int i = 1; i < n; i++) {
      if (((p[i - 1] + 1) - 'a') % 26 + 'a' == p[i])
        len++;
      else
        len = 1;
      char c = p[i] - 'a';
      cnt[c] = max(cnt[c], len);
    }
    for (auto i : cnt) res += i;
    return res;
  }
};

你可能感兴趣的:(467. 环绕字符串中唯一的子字符串)