Consecutive Characters LeetCode solution in Python
1# Runtime: 30 ms (Top 32.1%) | Memory: 13.25 MB (Top 75.9%)234class Solution(object):5def maxPower(self, s):6"""7:type s: str8:rtype: int9"""10stack = []11mxpow = 012for i in s:13if stack and stack[-1] != i:14mxpow = max(mxpow, len(stack))15stack = []16stack.append(i)17else:18stack.append(i)19mxpow = max(mxpow, len(stack))20return mxpow