详见:https://leetcode.com/problems/unique-substrings-in-wraparound-string/description/

C++:

class Solution {
public:
    int findSubstringInWraproundString(string p) 
    {
        vector<int> cnt(26, 0);
        int len = 0;
        for (int i = 0; i < p.size(); ++i) 
        {
            if (i > 0 && (p[i] == p[i - 1] + 1 || p[i - 1] - p[i] == 25)) 
            {
                ++len;
            } 
            else
            {
                len = 1;
            }
            cnt[p[i] - 'a'] = max(cnt[p[i] - 'a'], len);
        }
        return accumulate(cnt.begin(), cnt.end(), 0);
    }
};

 参考:https://www.cnblogs.com/grandyang/p/6143071.html

相关文章:

  • 2021-06-09
  • 2021-12-15
  • 2022-02-01
  • 2021-11-19
  • 2021-06-28
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
相关资源
相似解决方案