Environment: Python 3.8
Key technique: for, if, !=
A string is good if there are no repeated characters.
Given a string
s, return the number of good substrings of length three in
Note that if there are multiple occurrences of the same substring, every occurrence should be counted.
A substring is a contiguous sequence of characters in a string.
Input: s = "xyzzaz"
Explanation: There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz".
The only good substring of length 3 is "xyz".
- if s[i] != s[i+1] and s[i] != s[i+2] and s[i+1] !=s[i+2], ans+=1.
- Return ans
def countGoodSubstrings(self, s):
for i in range(len(s)-2):
if (s[i] != s[i+1] and s[i] != s[i+2] and s[i+1] !=s[i+2]):