diff --git a/1358. Number of Substrings Containing All Three Characters b/1358. Number of Substrings Containing All Three Characters new file mode 100644 index 0000000..0485cc3 --- /dev/null +++ b/1358. Number of Substrings Containing All Three Characters @@ -0,0 +1,18 @@ +class Solution { +public: + int numberOfSubstrings(std::string s) { + std::vector count(3, 0); + int left = 0; + int result = 0; + for (int i = 0; i < s.length(); i++) { + count[s[i] - 'a']++; + + while (count[0] > 0 && count[1] > 0 && count[2] > 0) { + result += s.length() - i; + count[s[left] - 'a']--; + left++; + } + } + return result; + } +};