Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- js ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ฐฑ์ค 2108 nodejs
- js ๋ฌธ์์ด ์์ถ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- emtion app router
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ์ต์ ๋์ฒด์ด๋
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- ์ค์ฝํ
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ์นด์นด์ค ์ฝํ
- app router emotion
- suspense react-query
- suspense ๋น๋๊ธฐ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- suspense ๋์์๋ฆฌ
- suspense ๋ณ๋ชฉํ์
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๋ฐฑ์ค 1339๋ฒ js
- emotion RSC
- js
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ๊ตฌ๋ฆํค
- next13 emotion
- ์ฌ์ฉ์ฑ ๊ฐ์
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 1920๋ฒ] ์ ์ฐพ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 1920๋ฒ] ์ ์ฐพ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 2. 3. 20:08728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/1920
const fs = require('fs');
const input = fs.readFileSync('dev/stdin').toString().trim().split('\n');
const binarySearch = (arr, num) => {
let start = 0;
let end = arr.length - 1;
while (start <= end) {
let middle = Math.floor((start + end) / 2);
if (arr[middle] < num) {
start = middle + 1;
} else if (arr[middle] > num) {
end = middle - 1;
} else {
return 1;
}
}
return 0;
};
const haveCard = input[1]
.split(' ')
.sort((a, b) => a - b)
.map(Number);
const isCard = input[3].split(' ').map(Number);
const answer = isCard.map((v) => {
return binarySearch(haveCard, v);
});
console.log(answer.join('\n'));
์์ฃผ ์ฌ์ด ๋ก์ง์ด์ง๋ง, ์ด๋ถ ํ์์ ๊ตฌํํ์ง ์์ผ๋ฉด ์๊ฐ์ด๊ณผ๋ก ํ๋ฆฌ์ง ์๋๋ค.
O(N) ๋ณต์ก๋๊ฐ ์๋ O(logN)์ธ ์ด๋ถ ํ์์ผ๋ก ๊ตฌํํ๋ฉด ๋น ๋ฅด๊ฒ ์๋ํด ํ ์ ์๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 3085๋ฒ] ์ฌํ๊ฒ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.06 |
---|---|
[๋ฐฑ์ค 6603๋ฒ] ๋ก๋ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.06 |
[๋ฐฑ์ค 10816๋ฒ] ์ซ์ ์นด๋2 - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.03 |
[๋ฐฑ์ค 14719๋ฒ] ๋น๋ฌผ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.28 |
[๋ฐฑ์ค 3009๋ฒ] ๋ค ๋ฒ์งธ ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.25 |
Comments