Easy

Quiz

#1446 Consecutive Characters

APPROACH

Define the power of a string as the length of its longest non-empty run of identical characters. Given a string s, compute and return its power.

Example 1:

Input: s = "leetcode"
Output: 2
Explanation: The substring "ee" is of length 2 with the character 'e' only.

Example 2:

Input: s = "abbcccddddeeeeedcba"
Output: 5
Explanation: The substring "eeeee" is of length 5 with the character 'e' only.
1 of 4
1:00

What is the optimal approach for this problem?