Skip to content

Commit 4daf7e4

Browse files
authored
[JustDevRae] 25.01.09 (#15)
* remove smallest number / 중급 * divisible numbers array / 중급 * duplicate number count / 기초 * matrix addition / 중급 * array element length / 기초 * rotate array / 기초 * slice array / 기초 * array algorithm md file * reverse string / 기초 * control Z / 기초 * dart game / 중급 * valid parentheses / 중급 * crane claw game / 중급
1 parent 0aa1996 commit 4daf7e4

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

JustDevRae/Stack/control_Z.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function solution(s) {
2+
var answer = 0;
3+
let Z = 0;
4+
const controlArray = s.split(" ");
5+
for (let i = 0; i < controlArray.length; i++) {
6+
if (controlArray[i] == "Z") {
7+
answer -= Z;
8+
continue;
9+
}
10+
answer += Number(controlArray[i]);
11+
Z = Number(controlArray[i]);
12+
}
13+
14+
return answer;
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function solution(board, moves) {
2+
let answer = 0;
3+
const stack = [];
4+
5+
for (let move of moves) {
6+
for (let i = 0; i < board.length; i++) {
7+
if (board[i][move - 1] !== 0) {
8+
let doll = board[i][move - 1];
9+
board[i][move - 1] = 0;
10+
11+
if (stack.length > 0 && stack[stack.length - 1] === doll) {
12+
stack.pop();
13+
answer += 2;
14+
} else {
15+
stack.push(doll);
16+
}
17+
break;
18+
}
19+
}
20+
}
21+
22+
return answer;
23+
}

JustDevRae/Stack/dart_game.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function solution(dartResult) {
2+
var answer = 0;
3+
const dartResultArray = dartResult.match(/\d+|[SDT]|\#|\*/g);
4+
const stack = [];
5+
let value;
6+
7+
for (str of dartResultArray) {
8+
if (str === "S") {
9+
value = stack.pop();
10+
stack.push(value);
11+
} else if (str === "D") {
12+
value = stack.pop();
13+
stack.push(value * value);
14+
} else if (str === "T") {
15+
value = stack.pop();
16+
stack.push(value * value * value);
17+
} else if (str === "*") {
18+
let firtPopValue = stack.pop();
19+
firtPopValue *= 2;
20+
let secondPopValue = stack.pop();
21+
if (secondPopValue === undefined) {
22+
stack.push(firtPopValue);
23+
} else {
24+
secondPopValue *= 2;
25+
stack.push(secondPopValue);
26+
stack.push(firtPopValue);
27+
}
28+
} else if (str === "#") {
29+
value = stack.pop();
30+
stack.push(value * -1);
31+
} else {
32+
stack.push(Number(str));
33+
}
34+
}
35+
36+
for (element of stack) {
37+
answer += element;
38+
}
39+
40+
return answer;
41+
}

JustDevRae/Stack/reverse_string.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function solution(my_string) {
2+
var answer = "";
3+
const string = [...my_string];
4+
5+
for (let i = 0; i < my_string.length; i++) {
6+
answer += string.pop();
7+
}
8+
9+
return answer;
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function solution(s) {
2+
const stack = [];
3+
for (const c of s) {
4+
if (c === "(") {
5+
stack.push(c);
6+
} else if (c === ")") {
7+
if (stack.length === 0) {
8+
continue;
9+
} else {
10+
stack.pop();
11+
}
12+
}
13+
}
14+
15+
return stack.length === 0;
16+
}

0 commit comments

Comments
 (0)