-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAll3characters.cpp
More file actions
34 lines (34 loc) · 823 Bytes
/
All3characters.cpp
File metadata and controls
34 lines (34 loc) · 823 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
27
28
29
30
31
32
33
34
class Solution {
public:
int min1(int a,int b,int c)
{
return min(a,min(b,c));
}
int numberOfSubstrings(string s) {
/*int left=0,len=s.length(),right=0,con=0;
vector<int>freq(26,0);
for(right=0;right<len;right++)
{
freq[s[right]-'a']++;
while(freq[0] && freq[1] && freq[2])
{
freq[s[left]-'a']--;
left++;
}
con = con + left;
}
return con;*/
int l1=-1,l2=-1,l3=-1,i,len=s.length(),con=0;
for(i=0;i<len;i++)
{
if(s[i]=='a')
l1=i;
if(s[i]=='b')
l2=i;
if(s[i]=='c')
l3=i;
con = con + min1(l1,l2,l3) + 1;
}
return con;
}
};