1 题目描述
2 解题思路
很简单,从头到尾一次遍历即可,时间复杂度O(n),空间复杂度O(1)
class Solution:
def maxPower(self, s: str) -> int:
i=0
num=1
max_num=0
c=''
for i in s:
if(i==c):
num+=1
else:
c=i
num=1
if(num>max_num):
max_num=num
return(max_num)