회고
[개발일지] - 580(주말)
Happy Programmer
2025. 2. 2. 23:28
(1).백준 11728번 배열 합치기는 배열을 합쳐서 정렬하라는 문제였는데
그냥 concat이나 구조분해할당([...a, ...b]) 형태로 진행한 다음 sort를 써도 됐겠지만
이미 정렬된 내용이라고 해서 시간복잡도를 고려해서 둘 중 작은 값을 먼저 넣는 방식으로 진행했다.
const input = `4 3
2 3 5 9
1 4 7`.split('\n').map(el => el.split(' ').map(Number))
let index1 = 0
let index2 = 0
const result = []
while(index1 < input[0][0] || index2 < input[0][1]){
if(input[1][index1] < input[2][index2]){
result.push(input[1][index1])
index1++
}
else if(input[1][index1] > input[2][index2]){
result.push(input[2][index2])
index2++
}
else if(index1 < input[0][0]){
result.push(input[1][index1])
index1++
}
else{
result.push(input[2][index2])
index2++
}
}
console.log(result.join(' '))