function solution(s) {
var answer = 0;
var minLenWord = s;
var compressed = [];
for (var i = 1; i<=s.length; i++)
{
var index = 0;
var words = [];
while (index <= s.length){
var data = s.slice(index,index+i)
if (data !== ''){
words.push(data);
}
index += i
}
var temp = '';
var base = words[0];
var count = 1;
for(var j = 1; j<= words.length; j++){
if (j === words.length){
if (count >1)
{
temp += count.toString() + base;
}
else{
temp += base;
}
}
else if (base === words[j])
{
count += 1;
}
else
{
if (count > 1){
temp += count.toString() + base;
}
else{
temp += base;
}
base = words[j];
count = 1;
}
}
if (temp.length < minLenWord.length)
{
minLenWord = temp;
}
}
answer = minLenWord.length;
return answer;
}
'๐ฏ CodingTest > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] (Javascript) ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ (0) | 2022.04.21 |
---|---|
[Programmers] (Javascript) ์คํ์ฑํ ๋ฐฉ (0) | 2022.04.21 |
[Programmers] (Javascript) [1์ฐจ] ๋น๋ฐ์ง๋ (0) | 2022.04.21 |
[Programmers] (Javascript) ์คํจ์จ (0) | 2022.04.21 |
[Programmers] (Javascript) ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ (0) | 2022.04.21 |