467. 环绕字符串中唯一的子字符串
作者:互联网
class Solution {
public:
int findSubstringInWraproundString(string p) {
int n = p.size();
if (n == 0)
return 0;
int sum = 0;
vector<int>record(26, 0);
for (int i = 0; i < n - 1; i++)
{
int k = i, count = 1;
while (p[k + 1] - p[k] == 1 || p[k] - p[k + 1] == 25)
{
k++;
count++;
}
if (record[p[i] - 'a'] < count)
record[p[i] - 'a'] = count;
}
if (record[p[p.size() - 1]-'a'] == 0)
record[p[p.size() - 1]-'a'] = 1;
for (int i = 0; i < 26; i++)
sum += record[i];
return sum;
}
};
标签:count,int,467,++,record,字符串,环绕,sum,size 来源: https://blog.csdn.net/Scarlett_Guan/article/details/99186341