Given a string s, return the total number of substrings that contain only one distinct letter.
Constraints:
s.length
s[i] consists of only lowercase English letters.
The key insight is that every position in the string ends some number of single-letter substrings, and that number equals the length of the current run of identical characters ending at that position. For example, if we are at the third consecutive a, the substrings ending here with only one distinct letter are a, aa, and aaa, which is runLength) and accumulating it into a total, we can compute the answer in a single pass without needing to explicitly enumerate ...
Given a string s, return the total number of substrings that contain only one distinct letter.
Constraints:
s.length
s[i] consists of only lowercase English letters.
The key insight is that every position in the string ends some number of single-letter substrings, and that number equals the length of the current run of identical characters ending at that position. For example, if we are at the third consecutive a, the substrings ending here with only one distinct letter are a, aa, and aaa, which is runLength) and accumulating it into a total, we can compute the answer in a single pass without needing to explicitly enumerate ...