Skip to content

Commit 1c43bad

Browse files
authored
Merge pull request #9 from toothlessdev/publish
publish: 백준 Baekjoon 알고리즘 문제풀이 팁 for NodeJS, JavaScript
2 parents 8ad1be6 + abdee81 commit 1c43bad

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

contents/posts/ProblemSolving/baekjoon-tip-for-nodejs.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 백준 Baekjoon 알고리즘 문제풀이 팁 for NodeJS, JavaScript
3-
createdAt: 2026-01-22
3+
createdAt: 2026-01-28
44
category: ProblemSolving
55
description: NodeJS 환경에서 Baekjoon 온라인 저지 문제를 풀때, 자료구조나 입력/출력 처리가 익숙하지 않은 분들을 위해 유용한 팁들을 정리했습니다.
66
comment: true
@@ -43,7 +43,7 @@ let input = fs
4343

4444
```javascript
4545
let input = fs
46-
.readFileSync(process.platform === "linux" ? "/dev/stdin" : 0)
46+
.readFileSync(process.platform === "linux" ? 0 : "./in.txt")
4747
.toString()
4848
.trim()
4949
.split(/\s+/); // 개행문자와 공백문자 모두를 기준으로 분리
@@ -83,7 +83,7 @@ for (let n = 0; n < N; n++) {
8383

8484
# ✍️ 출력 처리 꿀팁
8585

86-
## 1. 출력 빠르게 하기
86+
## 출력 빠르게 하기
8787

8888
가끔 출력이 많은 문제에서 `console.log()`를 여러번 호출하면 시간초과가 발생할 수 있습니다. 이럴 때는 출력값을 배열에 모아두었다가 한 번에 출력하면 시간초과가 발생하지 않습니다.
8989

@@ -220,6 +220,7 @@ class Queue {
220220
this.q[this.tail++] = v;
221221
}
222222
pop() {
223+
if (this.isEmpty()) return null;
223224
const v = this.q[this.head];
224225
delete this.q[this.head++];
225226
return v;
@@ -255,11 +256,13 @@ class Deque {
255256
this.dq[this.tail++] = v;
256257
}
257258
popFront() {
259+
if (this.isEmpty()) return null;
258260
const v = this.dq[this.head];
259261
delete this.dq[this.head++];
260262
return v;
261263
}
262264
popBack() {
265+
if (this.isEmpty()) return null;
263266
const v = this.dq[--this.tail];
264267
delete this.dq[this.tail];
265268
return v;
@@ -303,7 +306,7 @@ class MaxHeap {
303306
}
304307
}
305308
pop() {
306-
if (this.heap.length === 1) return 0;
309+
if (this.heap.length === 1) return null;
307310
if (this.heap.length === 2) return this.heap.pop();
308311

309312
const element = this.heap[1];
@@ -625,7 +628,7 @@ const char = String.fromCharCode(65); // 'A'
625628

626629
'A' 는 65, 'a' 는 97, '0' 은 48 의 아스키코드 값을 가집니다.
627630

628-
문자의 범위를 비교할때 `/\/[A-Z]/` 같은 정규표현식 대신 아스키코드 값을 비교하는 방법이 더 빠릅니다.
631+
문자의 범위를 비교할때 `/[A-Z]/` 같은 정규표현식 대신 아스키코드 값을 비교하는 방법이 더 빠릅니다.
629632

630633
```javascript
631634
const A = "A".charCodeAt(0);
@@ -661,10 +664,6 @@ for (...) chars.push(x);
661664
let str = chars.join('');
662665
```
663666

664-
```javascript
665-
666-
```
667-
668667
<br><br>
669668

670669
# ✍️ 정렬
@@ -737,7 +736,7 @@ JSON.stringify({ key: NaN }); // '{"key":null}'
737736
JSON.stringify({ key: Infinity }); // '{"key":null}'
738737
```
739738

740-
### 비트마스킹시 주의사항
739+
## 비트마스킹시 주의사항
741740

742741
비트마스킹을 사용하면 집합을 효율적으로 표현하고, 비트 연산을 통해 빠르게 집합 연산을 수행할 수 있습니다.
743742

@@ -773,3 +772,9 @@ let mask = 0n;
773772

774773
mask |= 1n << 40n;
775774
```
775+
776+
<br><br><br><br>
777+
778+
UnionFind, SegmentTree, Trie 와 같은 고급 자료구조나 직접적인 알고리즘들은 따로 다루지 않았습니다. <br/>
779+
다른 팁들이 생기면 계속 추가할 예정입니다. 😊 <br/>
780+
추가하면 좋을 내용이 있다면 댓글로 알려주세요 🙌

0 commit comments

Comments
 (0)