-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path467.cpp
More file actions
24 lines (24 loc) · 685 Bytes
/
Copy path467.cpp
File metadata and controls
24 lines (24 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
int findSubstringInWraproundString(string p) {
int n = p.size();
if (n == 0)
return 0;
vector<int> con(26, 0);
con[p[0] - 'a'] = 1;
int sum = 0, len = 1;
for (int i = 1; i < n; ++i) {
if ((p[i] == p[i - 1] + 1))
con[p[i] - 'a'] = max(++len, con[p[i] - 'a']);
else if (p[i] == p[i - 1] - 25)
con[0] = max(++len, con[0]);
else {
con[p[i] - 'a'] = max(con[p[i] - 'a'], 1);
len = 1;
}
}
for (int i = 0; i < 26; ++i)
sum += con[i];
return sum;
}
};