function solution(X = "12321", Y = "42531") {
const countX = Array(10).fill(0);
const countY = Array(10).fill(0);
for (const digit of X) countX[Number(digit)]++;
for (const digit of Y) countY[Number(digit)]++;
let result = '';
for (let i = 9; i >= 0; i--) {
const commonCount = Math.min(countX[i], countY[i]);
result += String(i).repeat(commonCount);
}
if (result === '') return '-1';
if (result === "0".repeat(result.length)) return '0';
return result;
}'CodeKata > JS' 카테고리의 다른 글
| Code_Kata_js_문자열 나누기 (0) | 2024.12.23 |
|---|---|
| CodeKata_js_체육복 (0) | 2024.12.20 |
| 옹알이(2) (1) | 2024.12.18 |
| CodeKata_js_덧칠하기 (0) | 2024.12.03 |
| Codekata_js_소수만들기 (0) | 2024.12.02 |
댓글