Algorithm
- ๋ฃ๋ณด์ก -
๋ฌธ์
๊น์ง์์ด ๋ฃ๋ ๋ชปํ ์ฌ๋์ ๋ช ๋จ๊ณผ, ๋ณด๋ ๋ชปํ ์ฌ๋์ ๋ช ๋จ์ด ์ฃผ์ด์ง ๋, ๋ฃ๋ ๋ณด๋ ๋ชปํ ์ฌ๋์ ๋ช ๋จ์ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
let fs = require("fs");
let input = fs.readFileSync("/dev/stdin")
.toString()
.trim()
.split("\n");
let count = input
.splice(0, 1)[0]
.split(" ")
.map((el) => Number(el));
let noSound = input.splice(0, count[0]);
let noSee = input.splice(0, count[1]);
function findValue(name, arr) {
let start = 0;
let end = arr.length - 1;
let mid;
while (start <= end) {
mid = Math.floor((start + end) / 2);
if (arr[mid] > name) end = mid - 1;
else if (arr[mid] < name) start = mid + 1;
else return true;
}
return false;
}
let [short, long] =
noSound.length > noSee.length ? [noSee, noSound] : [noSound, noSee];
short.sort();
long.sort();
let result = short.filter((el) => findValue(el, long));
result.sort();
console.log(result.length + "\n" + result.join("\n"));
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 1924๋ฒ : 2007๋ (0) | 2021.07.17 |
---|---|
[๋ฐฑ์ค][Node.js] 1919๋ฒ : ์ ๋๊ทธ๋จ ๋ง๋ค๊ธฐ (0) | 2021.07.16 |
[๋ฐฑ์ค][Node.js] 1748๋ฒ : ์ ์ด์ด ์ฐ๊ธฐ 1 (0) | 2021.07.14 |
[๋ฐฑ์ค][Node.js] 1712๋ฒ : ์์ต๋ถ๊ธฐ์ (0) | 2021.07.14 |
[๋ฐฑ์ค][Node.js] 1697๋ฒ : ์จ๋ฐ๊ผญ์ง (0) | 2021.07.12 |
๋๊ธ