Python 3 | Two Pointers | Explanation
Explanation\n- Two pointer to same direction, fast pointer check new character, slow pointer shorten substr\n- Use a little math (n-j) to count possible valid s
### Explanation\n- Two pointer to same direction, fast pointer check new character, slow pointer shorten substr\n- Use a little math (`n-j`) to count possible valid substrings\n- Check comments for more detail\n### Implementation\n```\nclass Solution:\n    def numberOfSubstrings(self, s: str) -> int:\n        a = b = c = 0                        # counter for letter a/b/c\n        ans, i, n = 0, 0, len(s)             # i: slow pointer\n        for j, letter in enumerate(s):       # j: fast pointer\n            if letter == \'a\': a += 1         # increment a/b/c accordingly\n            elif letter == \'b\': b += 1\n            else: c += 1\n            while a > 0 and b > 0 and c > 0: # if all of a/b/c are contained, move slow pointer\n                ans += n-j                   # count possible substr, if a substr ends at j, then there are n-j substrs to the right that are containing all a/b/c\n                if s[i] == \'a\': a -= 1       # decrement counter accordingly\n                elif s[i] == \'b\': b -= 1\n                else: c -= 1\n                i += 1                       # move slow pointer\n        return ans    \n```
['Two Pointers', 'Python', 'Python3']