-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* [이분탐색 문제] | ||
* - 언제 포인터를 증가해야할지 한참 고민했다. | ||
*/ | ||
|
||
let inputs = require("fs") | ||
.readFileSync("/dev/stdin") | ||
.toString() | ||
.trim() | ||
.split("\n"); | ||
|
||
const solution = (inputs) => { | ||
const [lenA, lenB] = inputs[0].split(" ").map((v) => +v); | ||
const arrA = inputs[1] | ||
.split(" ") | ||
.map((v) => +v) | ||
.sort((a, b) => a - b); | ||
const arrB = inputs[2] | ||
.split(" ") | ||
.map((v) => +v) | ||
.sort((a, b) => a - b); | ||
|
||
let [at, bt] = [0, 0]; | ||
let answer = []; | ||
|
||
while (at < lenA && bt < lenB) { | ||
if (arrA[at] < arrB[bt]) { | ||
answer.push(arrA[at]); | ||
at++; | ||
} else if (arrA[at] > arrB[bt]) { | ||
bt++; | ||
} else { | ||
at++; | ||
bt++; | ||
} | ||
} | ||
|
||
// 남은 A 넣기 | ||
for (let i = at; i < lenA; i++) { | ||
answer.push(arrA[i]); | ||
} | ||
|
||
console.log(answer.length); | ||
if (answer.length > 0) console.log(answer.join(" ")); | ||
}; | ||
|
||
solution(inputs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters