
😎풀이
nums1과 nums2 오름차 순 정렬
- Set객체를 통해 정렬된 각 배열 변환
2-1. 교집합이 있는지 탐색하며 최솟값 갱신
- 정렬된
nums1과 nums2 순회
- 더 작은 수를 십의 자리로, 더 큰 수를 일의 자리로 설정하여 두 자리로 만들 수 있는 최솟값 생성
- 최솟값 갱신
- 탐색된 최솟값 반환
function minNumber(nums1: number[], nums2: number[]): number {
let min = Infinity
const sorted1 = nums1.toSorted((a, b) => a - b)
const sorted2 = nums2.toSorted((a, b) => a - b)
const set1 = new Set(sorted1)
const set2 = new Set(sorted2)
for(const num of set1) {
if(set2.has(num)) {
min = Math.min(min, num)
}
}
const len = Math.min(set1.size, set2.size)
for(let i = 0; i < len; i++) {
const num1 = sorted1[i]
const num2 = sorted2[i]
const less = Math.min(num1, num2)
const more = Math.max(num1, num2)
const strNum = String(less) + String(more)
const num = Number(strNum)
min = Math.min(min, num)
}
return min
};