1446. Consecutive Characters 發表於 2023-02-13 | 分類於 leetcode problemsolution12345678910111213141516171819class Solution {public: int maxPower(string s) { int count = 1, ret= 1, n =s.size(); char val = s[0]; for(int i=1;i<n;++i){ if(val == s[i]){ count++; } else{ ret = max(ret,count); count =1; val = s[i]; } } ret = max(ret,count); return ret; }}; analysis time complexity O(n) space complexity O(1)