java.lang.Object
g1801_1900.s1876_substrings_of_size_three_with_distinct_characters.Solution

public class Solution extends Object
1876 - Substrings of Size Three with Distinct Characters.<p>Easy</p> <p>A string is <strong>good</strong> if there are no repeated characters.</p> <p>Given a string <code>s</code>, return <em>the number of <strong>good substrings</strong> of length <strong>three</strong> in</em> <code>s</code>.</p> <p>Note that if there are multiple occurrences of the same substring, every occurrence should be counted.</p> <p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;xyzzaz&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> There are 4 substrings of size 3: &ldquo;xyz&rdquo;, &ldquo;yzz&rdquo;, &ldquo;zza&rdquo;, and &ldquo;zaz&rdquo;. The only good substring of length 3 is &ldquo;xyz&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;aababcabc&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> There are 7 substrings of size 3: &ldquo;aab&rdquo;, &ldquo;aba&rdquo;, &ldquo;bab&rdquo;, &ldquo;abc&rdquo;, &ldquo;bca&rdquo;, &ldquo;cab&rdquo;, and &ldquo;abc&rdquo;. The good substrings are &ldquo;abc&rdquo;, &ldquo;bca&rdquo;, &ldquo;cab&rdquo;, and &ldquo;abc&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countGoodSubstrings

      public int countGoodSubstrings(String s)