-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path467.cpp
More file actions
26 lines (26 loc) · 678 Bytes
/
467.cpp
File metadata and controls
26 lines (26 loc) · 678 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
25
26
class Solution {
public:
int findSubstringInWraproundString(string p) {
int n = p.size();
if(n<2)
return n;
int alpha[26];
memset(alpha,0,sizeof(alpha));
alpha[p[0]-'a']++;
int count = 1;
for(int i=1; i<n; i++){
if((p[i] == p[i-1]+1) || (p[i-1]=='z' && p[i] =='a')){
count++;
alpha[p[i]-'a'] = max(alpha[p[i]-'a'], count);
}
else{
alpha[p[i]-'a'] = max(alpha[p[i]-'a'],1);
count = 1;
}
}
int res = 0;
for(auto x: alpha)
res += x;
return res;
}
};