function solution(s) {
var answer = 0;
if(s.length===1){
return 1;
}
let ans = Infinity;
for(let rate=1; rate<=s.length/2; rate++){
let compressed = '';
let current =0;
let next = rate;
while(current < s.length){
const currentStr = s.slice(current, current + rate);
let nextStr = s.slice(next, next + rate);
let count = 1;
while(currentStr === nextStr){
count++;
next += rate;
nextStr = s.slice(next, next + rate);
}
compressed += count === 1 ? currentStr : count + currentStr;
current = next;
next = current + rate;
}
ans = Math.min(ans, compressed.length);
}
return ans;
}
문자열 압축
Level
프로그래머스 Lv2
Day
9일
kakao
2020 카카오 블라인드