LC: 1180. Count Substrings with Only One Distinct Letter - spiralgo/algorithms GitHub Wiki
1180. Count Substrings with Only One Distinct Letter:
The Essence:
- When another character is appended to a string,
nnew substrings are formed, which are added to the number of substrings of the previous string. - We can count the running length of a substring with same character, and add its length at each iteration to the total, thus also adding the number of substrings of that string.
Details:
This can be done using a basic loop through the characters. If two adjacent characters are same, we increment the running length. Otherwise, it's reset to 0. The running length is then added to the total.