Given a string s
consisting only of characters a, b and c.
Return the number of substrings containing at least one occurrence of all these characters a, b and c.
Input: s = "abcabc" Output: 10 Explanation: The substrings containing at least one occurrence of the characters a, b and c are "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc" and "abc" (again).
Input: s = "aaacb" Output: 3 Explanation: The substrings containing at least one occurrence of the characters a, b and c are "aaacb", "aacb" and "acb".
Input: s = "abc" Output: 1
3 <= s.length <= 5 x 10^4
s
only consists of a, b or c characters.
impl Solution {
pub fn number_of_substrings(s: String) -> i32 {
let s = s.as_bytes();
let mut count = [0; 3];
let mut i = 0;
let mut ret = 0;
for j in 0..s.len() {
count[(s[j] - b'a') as usize] += 1;
while count[0] * count[1] * count[2] > 0 {
count[(s[i] - b'a') as usize] -= 1;
i += 1;
}
ret += i;
}
ret as i32
}
}