Leetcode 1542 Solution

This article provides solution to leetcode question 1542 (consecutive-characters)

https://leetcode.com/problems/consecutive-characters

Solution

class Solution:
    def maxPower(self, s: str) -> int:
        res = 0
        last_ch = None
        cur_len = 0

        for ch in s:
            if ch == last_ch:
                cur_len += 1
            else:
                cur_len = 1

            res = max(res, cur_len)
            last_ch = ch

        return res