We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fc84bbf commit a87ae88Copy full SHA for a87ae88
1 file changed
live8/test88/문제2/황장현.js
@@ -0,0 +1,34 @@
1
+const input = require('fs')
2
+ .readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3
+ .toString()
4
+ .trim()
5
+ .split('\n')
6
+ .map((el) => el.split(' ').map(Number));
7
+
8
+function solution(input) {
9
+ const [N, M] = input[0];
10
+ const A = input[1];
11
+ const B = input[2];
12
+ let p1 = 0;
13
+ let p2 = 0;
14
15
+ const result = [];
16
17
+ while (p1 < N && p2 < M) {
18
+ if (A[p1] < B[p2]) {
19
+ result.push(A[p1++]);
20
+ } else if (A[p1] > B[p2]) {
21
+ result.push(B[p2++]);
22
+ } else {
23
+ result.push(A[p1], B[p2]);
24
+ p1++;
25
+ p2++;
26
+ }
27
28
+ while (p1 < N) result.push(A[p1++]);
29
+ while (p2 < M) result.push(B[p2++]);
30
31
+ return result.join(' ');
32
+}
33
34
+console.log(solution(input));
0 commit comments