1542. Consecutive Characters
My accepted Python solution to LeetCode problem 1542, Consecutive Characters, running in 7ms.
- Difficulty: Easy
- Python
- Runtime 7ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 17.3MB, accepted 2025-12-29.
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