LeetCode 1180, Easy. Topics: Math, String. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 24 parametrized pytest cases, and a playground notebook:
Problem
Given a string s, return the number of substrings that have only one distinct letter.
Examples
Constraints
- 1 <= s.length <= 1000
s consists of only lowercase English letters.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026