Skip to content

Commit ca7a085

Browse files
committed
투포인터 > 배열 합치기
1 parent 2950703 commit ca7a085

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

part9/1.배열합치기.txt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const fs = require("fs")
2+
let input = fs.readFileSync("index.txt").toString().split("\n")
3+
4+
5+
let [n,m]=input[0].split(" ").map(Number)
6+
7+
let a =input[1].split(" ").map(Number)
8+
let b= input[2].split(" ").map(Number)
9+
10+
let result=[];
11+
let i=0;
12+
let j=0;
13+
14+
while(i<n&&j<m){
15+
if(a[i]<b[j]){
16+
17+
result.push(a[i])
18+
i+=1;
19+
20+
}else {
21+
22+
result.push(b[j])
23+
j+=1;
24+
25+
}
26+
}
27+
28+
while(i<n){
29+
result.push(a[i]);
30+
i+=1
31+
}
32+
33+
while(j<n){
34+
result.push(b[j])
35+
j+=1
36+
}
37+
38+
console.log(result.join(" "))

0 commit comments

Comments
 (0)