-
Notifications
You must be signed in to change notification settings - Fork 0
1446_ConsecutiveCharacters
a920604a edited this page Apr 14, 2023
·
1 revision
class 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;
}
};
- time complexity
O(n)
- space complexity
O(1)
footer