Leetcode 1876: Substrings of Size Three with Distinct Characters
In this problem (https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/), we want to count the number of substring of length 3(i.e. 3 characters in a row in the string), such that these substring don’t contain duplicate characters.
Given n the length of the input string, we can solve the problem by testing all the substrings of length 3. The number of substrings of length 3 is
n — 2, that is
O(n). For each of the substring, we only need to compare the 3 characters with 3 comparisons, that is…