Back to all posts
가장 큰 수
Written by ppotatoG & Posted on November 18th, 2021
제출한 답
sort를 진짜 극한으로 사용했다
function solution(num) {num.sort((a, b) => {let num1 = String(a);let num2 = String(b);if(num1.length > num2.length){if(num1 + '' + num2 > num2 + '' + num1) return 1;if(num1 + '' + num2 < num2 + '' + num1) return -1;}if(num1.length < num2.length){if(num1 + '' + num2 > num2 + '' + num1) return 1;if(num1 + '' + num2 < num2 + '' + num1) return -1;}if(num1.slice(0, 1) > num2.slice(0, 1)) return 1;if(num1.slice(0, 1) < num2.slice(0, 1)) return -1;if(num1.slice(1, 2) > num2.slice(1, 2)) return 1;if(num1.slice(1, 2) < num2.slice(1, 2)) return -1;if(num1.slice(2,3) > num2.slice(2,3)) return 1;if(num1.slice(2,3) < num2.slice(2,3)) return -1;return 0;}).reverse();return num[0] === 0 ? String(0) : num.join(' ');}
최근 보충한 답
다른사람 풀이를 참고한 답
function solution(arr) {arr = arr.sort((a, b) => `${b}${a}` - `${a}${b}`);return arr[1] === 0 ? '0' : arr.join('');}