1446. Consecutive Characters

Consecutive Characters - LeetCode The power of the string is the maximum length of a non-empty substring that contains only one unique character. Given a string s, return the power of s.

Example 1: Input: s = “leetcode” Output: 2 Explanation: The substring “ee” is of length 2 with the character ‘e’ only.

  • code
class Solution:
    def maxPower(self, s: str) -> int:
        start = 0
        res = i = 1
        while i < len(s):
            if s[i] == s[start]:
                res = max(res, i - start + 1)
            else:
                start = i
            i += 1
        return res