728x90
const decompression = function (image) {
let result = '';
const decom = (x, y, len) => {
let isSame = true;
if(len === 1) {
return '' + image[x][y];
}
for(let i=0; i<len; i++) {
for(let j=0; j<len; j++) {
if(image[x][y] !== image[x+i][y+j]) {
isSame = false;
break;
}
}
if(!isSame) break;
}
if(isSame) return '' + image[x][y];
len = len / 2;
let str = 'X';
str += decom(x, y, len);
str += decom(x, y+len, len);
str += decom(x+len, y, len);
str += decom(x+len, y+len, len);
return str;
}
result = decom(0,0,image.length);
return result;
};
https://www.soyou.space/1d58f17d-3273-4d31-bd8a-0c7fabfad8a8
반응형
'BEB > algorithm' 카테고리의 다른 글
| 41_countIslands (0) | 2022.12.22 |
|---|---|
| 40_longestPalindrome 가장긴 팰린드롬 (0) | 2022.12.20 |
| 37_coinChange (0) | 2022.12.15 |
| 34_LCS (Longest Common Subsequence) (0) | 2022.12.12 |
| 33 LIS (Longest Increasing Sequence) 가장 긴 증가하는 수열 (0) | 2022.12.09 |
댓글