[Java/C++/Python] Easy and Concise
Solution 1: Sliding Window\nFind many similar sliding window problem at the end of post.\n\nTime O(N)\nSpace O(1)\n\n\nJava:\njava\n    public int numberOfSubst
## Solution 1: Sliding Window\nFind many similar sliding window problem at the end of post.\n\nTime `O(N)`\nSpace `O(1)`\n<br>\n\n**Java:**\n```java\n    public int numberOfSubstrings(String s) {\n        int count[] = {0, 0, 0}, res = 0 , i = 0, n = s.length();\n        for (int j = 0; j < n; ++j) {\n            ++count[s.charAt(j) - \'a\'];\n            while (count[0] > 0 && count[1] > 0 && count[2] > 0)\n                --count[s.charAt(i++) - \'a\'];\n            res += i;\n        }\n        return res;\n    }\n```\n\n**C++:**\n```cpp\n    int numberOfSubstrings(string s) {\n        int count[3] = {0, 0, 0},res = 0 , i = 0, n = s.length();\n        for (int j = 0; j < n; ++j) {\n            ++count[s[j] - \'a\'];\n            while (count[0] && count[1] && count[2])\n                --count[s[i++] - \'a\'];\n            res += i;\n        }\n        return res;\n    }\n```\n\n**Python:**\n```python\n    def numberOfSubstrings(self, s):\n        res = i = 0\n        count = {c: 0 for c in \'abc\'}\n        for j in xrange(len(s)):\n            count[s[j]] += 1\n            while all(count.values()):\n                count[s[i]] -= 1\n                i += 1\n            res += i\n        return res\n```\n<br>\n\n# Solution II\n`last` will record the position of last occurrence.\nIf the ending index of substring is `i`,\nthe starting position should be on the left of `min(last)`,\nin order to have all 3 different letters.\nAnd in this case, the starting index can be in range `[0, min(last)]`,\n`min(last) + 1` in total.\n\nTime `O(N)`\nSpace `O(1)`\n<br>\n\n**Java**\n```java\n    public int numberOfSubstrings(String s) {\n        int last[] = {-1, -1, -1}, res = 0, n = s.length();\n        for (int i = 0; i < n; ++i) {\n            last[s.charAt(i) - \'a\'] = i;\n            res += 1 + Math.min(last[0], Math.min(last[1], last[2]));\n        }\n        return res;\n    }\n```\n**C++**\n```cpp\n    int numberOfSubstrings(string s) {\n        int last[3] = {-1, -1, -1}, res = 0, n = s.length();\n        for (int i = 0; i < n; ++i) {\n            last[s[i] - \'a\'] = i;\n            res += 1 + min({last[0], last[1], last[2]});\n        }\n        return res;\n    }\n```\n**Python**\n```py\n    def numberOfSubstrings(self, s):\n        res, last = 0, [-1] * 3\n        for i, c in enumerate(s):\n            last[ord(c) - 97] = i\n            res += 1 + min(last)\n        return res\n```\n<br>\n\n# More Similar Sliding Window Problems\nHere are some similar sliding window problems.\nAlso find more explanations.\nGood luck and have fun.\n\n\n- 1248. [Count Number of Nice Subarrays](https://leetcode.com/problems/count-number-of-nice-subarrays/discuss/419378/JavaC%2B%2BPython-Sliding-Window-atMost(K)-atMost(K-1))\n- 1234. [Replace the Substring for Balanced String](https://leetcode.com/problems/replace-the-substring-for-balanced-string/discuss/408978/javacpython-sliding-window/367697)\n- 1004. [Max Consecutive Ones III](https://leetcode.com/problems/max-consecutive-ones-iii/discuss/247564/javacpython-sliding-window/379427?page=3)\n-  930. [Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/discuss/186683/)\n-  992. [Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/discuss/234482/JavaC%2B%2BPython-Sliding-Window-atMost(K)-atMost(K-1))\n-  904. [Fruit Into Baskets](https://leetcode.com/problems/fruit-into-baskets/discuss/170740/Sliding-Window-for-K-Elements)\n-  862. [Shortest Subarray with Sum at Least K](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/discuss/143726/C%2B%2BJavaPython-O(N)-Using-Deque)\n-  209. [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/discuss/433123/JavaC++Python-Sliding-Window)\n<br>
[]