179. Longest Continuous Repeating Character

EasyStringString

Given a string s, find and return the length of the longest substring that consists of a single repeated character.

Example: in 'aabbaab', the longest run is 'aa' (length 2).

Input: A single string s.

Output: An integer — the length of the longest run of a single repeated character.

Examples

Example 1
Input: aaabbb
Output: 3
Explanation: 'aaa' and 'bbb' both have length 3.
Example 2
Input: abccccd
Output: 4
Explanation: 'cccc' has length 4.
Example 3
Input: abcdef
Output: 1
Explanation: No character repeats consecutively.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →