Skip to content

๐Ÿ‘Š ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์ž

Notifications You must be signed in to change notification settings

haesoo-y/baekjoon-for-js

Repository files navigation

Baekjoon for JS

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ ๋ฌธ์ œ๋ฅผ ํ’€๋„๋ก ๋•๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ์ž…๋‹ˆ๋‹ค.

์ฝ”๋“œ ํ…œํ”Œ๋ฆฟ๊ณผ ์ถ”์ฒœ ๋ฌธ์ œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.


๐Ÿ”ฎ Template

  • JS๋Š” ๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์—์„œ ์ž‘๋™ํ•˜๋ฏ€๋กœ ๋ฐฑ์ค€ ์‚ฌ์ดํŠธ์˜ ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์œ„ํ•ด์„œ๋Š” Node JS ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • Node JS๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ์˜ ๋‘ ๊ฐ€์ง€ ํ…œํ”Œ๋ฆฟ์„ ๊ถŒ์žฅ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

basic

const fs = require('fs');
// TODO: ์ œ์ถœ ์‹œ ๊ฒฝ๋กœ ๋ณ€ํ™˜ ํ•„์ˆ˜ ("/dev/stdin")
const input = fs.readFileSync('test.txt').toString().trim().split('\n');

// ํ’€์ด
function solution(arr) {
  const [a, b] = arr[0].split(' ');
  return Number(a) + Number(b);
}

console.log(solution(input));

extended

const fs = require('fs');
// TODO: ์ œ์ถœ ์‹œ ๊ฒฝ๋กœ ๋ณ€ํ™˜ ํ•„์ˆ˜ ("/dev/stdin")
const input = fs.readFileSync('test.txt').toString().trim().split('\n');
// ์ •๋ฆฌ
/* ex.
const x = Number(input[0]);
const [y, z] = input[1].split(' ').map(v => Number(v));
const arr = input[2].split(' '); 
*/
// ํ’€์ด
function solution(x, y, z, arr) {
  const answer = [];
  return answer.join('\n');
}

console.log(solution(x, y, z, arr));
  • ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” test.txt์— ์ž‘์„ฑํ•˜์—ฌ ๋…ธ๋“œ ํ™˜๊ฒฝ์—์„œ ๋™์ž‘์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (ex. node my-solution.js)
  • ์ œ์ถœ ์‹œ ๊ฒฝ๋กœ๋Š” test.txt์—์„œ /dev/stdin์œผ๋กœ ๋ณ€๊ฒฝํ•ด์•ผ ์ •์ƒ์ ์œผ๋กœ ์ฑ„์ ์ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.
  • input๋ณ€์ˆ˜์— ๊ฐ ๋ผ์ธ์„ ๋‚˜๋ˆ„์–ด ๋ฐฐ์—ด๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
  • extended ํ…œํ”Œ๋ฆฟ์˜ ๊ฒฝ์šฐ solution ํ•จ์ˆ˜์— ๋„ฃ๊ธฐ ์ „ ๋ฏธ๋ฆฌ ์ •๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋‹ค๋ฅธ PS ํ”Œ๋žซํผ๊ณผ ์œ ์‚ฌํ•˜๊ฒŒ ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋‹ต์ด ํ•œ ์ค„์ผ ๊ฒฝ์šฐ basic์˜ return์ฒ˜๋Ÿผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
  • ์—ฌ๋Ÿฌ ์ค„์ผ ๊ฒฝ์šฐ ๋ฐ˜๋“œ์‹œ extended์˜ return๊ณผ ๊ฐ™์ด ๋ฐฐ์—ด๋‚ด์— ๋‹ต์„ ๋„ฃ์–ด join('\n')์œผ๋กœ ํ•˜๋‚˜์˜ string์œผ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ก Suggestion

  • ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ์— ์ฃผ๋กœ ๋‚˜์˜ค๋Š” ์œ ํ˜•์„ ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • JS๋ฅผ ์™„์ „ํžˆ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๋ฐฑ์ค€ ํ”Œ๋žซํผ ํŠน์„ฑ์ƒ ๋‹ค์Œ์˜ ๊ธฐ์ค€์— ์ ํ•ฉํ•œ ๋ฌธ์ œ๋“ค์„ ์„ ๋ณ„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
    • ๋งžํžŒ ์‚ฌ๋žŒ 1,000๋ช… ์ด์ƒ
    • JS๋กœ ํ‘ผ ์‚ฌ๋žŒ 10๋ช… ์ด์ƒ
    • ๋‚œ์ด๋„ ํ”Œ๋ž˜ํ‹ฐ๋„˜ ์ดํ•˜
  • ์œ„ ์กฐ๊ฑด์— ๋งž๋Š” ๋ฌธ์ œ๊ฐ€ 10๊ฐœ ์ดํ•˜์ผ ๊ฒฝ์šฐ, ์กฐ๊ฑด์— ๋งž์ง€ ์•Š๋”๋ผ๋„ ์ถฉ๋ถ„ํžˆ JS๋กœ ํ’€ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. (์ด ๊ฒฝ์šฐ ๋ฐ˜๋“œ์‹œ ์ง์ ‘ ํ’€๊ณ  ํ’€์ด ๋งํฌ ์ถ”๊ฐ€)
  • ๊ฐ ๋งํฌ๋ฅผ ํด๋ฆญํ•˜์—ฌ ํ•ด๋‹น ๋ฌธ์„œ๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Title Name Count Link
Implementation ๊ตฌํ˜„ 9 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Dynamic Programming ๋™์ ๊ณ„ํš๋ฒ• 7 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Greedy ๊ทธ๋ฆฌ๋”” 3 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Bruteforce ๋ธŒ๋ฃจํŠธํฌ์Šค 5 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Sorting ์ •๋ ฌ 5 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Binary Search ์ด๋ถ„ ํƒ์ƒ‰ 3 ๋ฐ”๋กœ๊ฐ€๊ธฐ
BFS & DFS ๋„ˆ๋น„ & ๊นŠ์ด ์šฐ์„ ํƒ์ƒ‰ 10 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Prefix Sum ๋ˆ„์ ํ•ฉ 4 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Dijkstra ๋‹ค์ต์ŠคํŠธ๋ผ 2 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Disjoint Set ๋ถ„๋ฆฌ ์ง‘ํ•ฉ 0 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Backtracking ๋ฐฑ ํŠธ๋ž˜ํ‚น 0 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Stack & Queue ์Šคํƒ & ํ 1 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Two Pointer ํˆฌ ํฌ์ธํ„ฐ 0 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Minimum Spanning Tree ์ตœ์†Œ ์ŠคํŒจ๋‹ ํŠธ๋ฆฌ 0 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Topological Sorting ์œ„์ƒ ์ •๋ ฌ 2 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Floyd-warshall ํ”Œ๋กœ์ด๋“œ ์™€์ƒฌ 2 ๋ฐ”๋กœ๊ฐ€๊ธฐ
Sliding Window ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ 3 ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿณ Contributor

Harry Mulgyeol KGC9175
  • ๊ธฐ์ค€์— ์ ํ•ฉํ•œ ๋ฌธ์ œ๋Š” ์–ธ์ œ๋“  PR์„ ๋‚จ๊ฒจ์ฃผ์„ธ์š”.
  • ์ปค๋ฐ‹ ์ปจ๋ฒค์…˜์€ ๊นƒ๋ชจ์ง€๋ฅผ ๋”ฐ๋ฅด๊ณ  ์žˆ์œผ๋ฉฐ ์ง€ํ‚ค์ง€ ์•Š์•„๋„ ์ข‹์Šต๋‹ˆ๋‹ค.
  • ๊ทธ ์™ธ ์ œ์•ˆํ•  ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ISSUE๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

About

๐Ÿ‘Š ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์ž

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published