Skip to content

Commit 3331f1a

Browse files
committed
Time: 38 ms (14.47%), Space: 21 MB (5.02%) - LeetHub
1 parent 1844cb7 commit 3331f1a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int numberOfSubstrings(string s) {
4+
int ans = 0;
5+
int n = s.size();
6+
map<char, int> mp;
7+
for (int l = 0, r = 0; r < n; r++) {
8+
mp[s[r]]++;
9+
while (mp.size() == 3) {
10+
ans += (n - r);
11+
mp[s[l]]--;
12+
if (mp[s[l]] == 0) mp.erase(s[l]);
13+
l++;
14+
}
15+
}
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)