|
1 | 1 | packagecom.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * 1358. Number of Substrings Containing All Three Characters |
5 |
| - * |
6 |
| - * Given a string s consisting only of characters a, b and c. |
7 |
| - * Return the number of substrings containing at least one occurrence of all these characters a, b and c. |
8 |
| - * |
9 |
| - * Example 1: |
10 |
| - * Input: s = "abcabc" |
11 |
| - * Output: 10 |
12 |
| - * 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). |
13 |
| - * |
14 |
| - * Example 2: |
15 |
| - * Input: s = "aaacb" |
16 |
| - * Output: 3 |
17 |
| - * Explanation: The substrings containing at least one occurrence of the characters a, b and c are "aaacb", "aacb" and "acb". |
18 |
| - * |
19 |
| - * Example 3: |
20 |
| - * Input: s = "abc" |
21 |
| - * Output: 1 |
22 |
| - * |
23 |
| - * Constraints: |
24 |
| - * 3 <= s.length <= 5 x 10^4 |
25 |
| - * s only consists of a, b or c characters. |
26 |
| - * */ |
27 | 3 | publicclass_1358 {
|
28 | 4 | publicstaticclassSolution1 {
|
29 |
| -/**A classic sliding window problem, no dp or backtracking, just sliding window: use two pointers. |
| 5 | +/** |
| 6 | + * A classic sliding window problem, no dp or backtracking, just sliding window: use two pointers. |
30 | 7 | * my new favorite queustion!
|
31 |
| - * */ |
| 8 | + */ |
32 | 9 | publicintnumberOfSubstrings(Strings) {
|
33 | 10 | int[]counts =newint[3];
|
34 | 11 | inti =0;
|
|