Skip to content

Instantly share code, notes, and snippets.

@yungyungGwon
Created August 29, 2020 09:09
Show Gist options
  • Save yungyungGwon/eb5aa62ea9d16a74043bd493378e7fb7 to your computer and use it in GitHub Desktop.
Save yungyungGwon/eb5aa62ea9d16a74043bd493378e7fb7 to your computer and use it in GitHub Desktop.
Algorithm
function solution(s){
var answer = 0;
var cnt = 0, check1 = "", check2 = "";
var length = [];
for(var i = 1; i < s.length; i++){
var strCh = "";
for(var j = 0; j < s.length;){
check1 = s.substr(j,i);
check2 = s.substr(j + i, i);
if(check1 == check2){
cnt++;
}
else{
if(cnt >= 1){
strCh += (cnt+1) + check1;
cnt = 0;
}
else{
strCh += check1;
cnt = 0;
}
}
j = j + i;
}
length.push(strCh.length);
}
answer = length[0];
for(var k = 0; k < length.length; k++){
if(answer > length[k]){
answer = length[k];
}
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment