Skip to content

Commit f4f4a07

Browse files
committed
[Add] Programmers_2022
1 parent ef9ed33 commit f4f4a07

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Programmers_2022/jun3Q1.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// link: https://programmers.co.kr/learn/courses/30/lessons/49994
2+
3+
function solution(dirs) {
4+
const move = { U: [0, 1], D: [0, -1], R: [1, 0], L: [-1, 0] };
5+
let curPoint = [0, 0];
6+
let visited = new Set();
7+
8+
for (let dir of dirs) {
9+
const nextX = curPoint[0] + move[dir][0];
10+
const nextY = curPoint[1] + move[dir][1];
11+
12+
if (Math.abs(nextX) > 5 || Math.abs(nextY) > 5) continue;
13+
14+
visited.add('' + curPoint[0] + curPoint[1] + nextX + nextY);
15+
visited.add('' + nextX + nextY + curPoint[0] + curPoint[1]);
16+
17+
curPoint = [nextX, nextY];
18+
}
19+
20+
return visited.size / 2;
21+
}

Programmers_2022/jun3Q2.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// link: https://programmers.co.kr/learn/courses/30/lessons/43165
2+
3+
function solution(numbers, target) {
4+
let answer = 0;
5+
6+
function dfs(sum, index) {
7+
if (index === numbers.length) {
8+
if (sum === target) answer += 1;
9+
return;
10+
}
11+
12+
dfs(sum + numbers[index], index + 1);
13+
dfs(sum - numbers[index], index + 1);
14+
}
15+
16+
dfs(0, 0);
17+
18+
return answer;
19+
}

Programmers_2022/jun3Q3.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// link: https://programmers.co.kr/learn/courses/30/lessons/12973
2+
3+
function solution(s) {
4+
let stack = [];
5+
6+
for (let i = 0; i < s.length; i++) {
7+
if (!stack.length || stack[stack.length - 1] !== s[i]) stack.push(s[i]);
8+
else stack.pop();
9+
}
10+
11+
return stack.length ? 0 : 1;
12+
}

0 commit comments

Comments
 (0)