• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Substrings of Size Three with Distinct Characters

    less than 1 minute read

    <-E 1876> Substrings of Size Three with Distinct Characters

    class Solution {
    public:
        int countGoodSubstrings(string s) {
            
            if(s.size() < 3)
                return 0;
            
            int ans = 0;
            
            for(int i = 0; i < s.size() - 2; i++)
            {
                if(s[i] != s[i+1] && s[i+1] != s[i+2] && s[i] != s[i+2])
                    ans++;
            }
            
            return ans;
        }
    };
    
    

    Tags: Algorithms, C++, Leetcode

    Updated: April 15, 2022

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.