LeetCode solutions

1542. Consecutive Characters

My accepted Python solution to LeetCode problem 1542, Consecutive Characters, running in 7ms.

  • Difficulty: Easy
  • Python
  • Runtime 7ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 7ms, memory 17.3MB, accepted 2025-12-29.

python
class Solution:
    def maxPower(self, s: str) -> int:
        max_power = 1
        current = 1
        for i in range(1, len(s)):
            if s[i] == s[i-1]:
                current += 1
                max_power = max(max_power, current)
            else:
                current = 1
        return max_power

Source