Problem · String
Count Substrings With Identical Characters
Learn this problemProblem statement
Given a string s, return the number of non-empty substrings in which all characters are identical.
Substrings are counted by their positions in s, so equal substring text occurring at different positions is counted separately.
Function
countIdenticalSubstrings(s: String) → intExamples
Example 1
s = "zzzyz"return = 8There are four one-character substrings equal to "z", two substrings equal to "zz", one substring equal to "zzz", and one substring equal to "y". The total is 4 + 2 + 1 + 1 = 8.
Example 2
s = "k"return = 1The only non-empty substring is "k", whose characters are identical.
Constraints
1 <= s.length <= 100scontains only lowercase English letters.