https://programmers.co.kr/learn/courses/30/lessons/60057
function solution(s) {
let answer = s.length;
for(let i = 1; i <= s.length; i++) {
const countList = new Array();
const stack = new Array();
for(let j = 0; j < s.length; j+=i) {
if(stack.length > 0) {
let temp = stack.pop();
stack.push(temp);
if(temp == s.slice(j, j+i)) {
countList.push(countList.pop()+1);
continue;
}
}
stack.push(s.slice(j, j+i));
countList.push(1);
}
answer = Math.min(answer, stack.join("").length
+ countList.filter((x)=>x>1).join("").length);
}
return answer;
}