문제 링크 : Consecutive Characters
/**
* @param {string} s
* @return {number}
*/
var maxPower = function(s) {
if(s.length === 1) return 1
let cntArr = []
let cnt = 1
for(let i=1; i<=s.length; i++ ) {
if(s[i] !== s[i-1]) {
cntArr.push(cnt)
cnt = 1
continue;
}else {
cnt++
if(i === s.length) cntArr.push(cnt)
}
}
return Math.max(...cntArr)
};
/**
* @param {string} s
* @return {number}
*/
var maxPower = function (s) {
let power = 1
let count = 1
for (i = 1; i <= s.length; i++) {
if (count > power) power = count
if (s[i] === s[i - 1]) {
count++
} else {
count = 1
}
}
return power
};