Skip to content

Commit e70965b

Browse files
authored
Create 1358. Number of Substrings Containing All Three Characters
1 parent af700c6 commit e70965b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int numberOfSubstrings(std::string s) {
4+
std::vector<int> count(3, 0);
5+
int left = 0;
6+
int result = 0;
7+
for (int i = 0; i < s.length(); i++) {
8+
count[s[i] - 'a']++;
9+
10+
while (count[0] > 0 && count[1] > 0 && count[2] > 0) {
11+
result += s.length() - i;
12+
count[s[left] - 'a']--;
13+
left++;
14+
}
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)