Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions JustDevRae/Stack/control_Z.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function solution(s) {
var answer = 0;
let Z = 0;
const controlArray = s.split(" ");
for (let i = 0; i < controlArray.length; i++) {
if (controlArray[i] == "Z") {
answer -= Z;
continue;
}
answer += Number(controlArray[i]);
Z = Number(controlArray[i]);
}

return answer;
}
23 changes: 23 additions & 0 deletions JustDevRae/Stack/crane_claw_game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function solution(board, moves) {
let answer = 0;
const stack = [];

for (let move of moves) {
for (let i = 0; i < board.length; i++) {
if (board[i][move - 1] !== 0) {
let doll = board[i][move - 1];
board[i][move - 1] = 0;

if (stack.length > 0 && stack[stack.length - 1] === doll) {
stack.pop();
answer += 2;
} else {
stack.push(doll);
}
break;
}
}
}

return answer;
}
41 changes: 41 additions & 0 deletions JustDevRae/Stack/dart_game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function solution(dartResult) {
var answer = 0;
const dartResultArray = dartResult.match(/\d+|[SDT]|\#|\*/g);
const stack = [];
let value;

for (str of dartResultArray) {
if (str === "S") {
value = stack.pop();
stack.push(value);
} else if (str === "D") {
value = stack.pop();
stack.push(value * value);
} else if (str === "T") {
value = stack.pop();
stack.push(value * value * value);
} else if (str === "*") {
let firtPopValue = stack.pop();
firtPopValue *= 2;
let secondPopValue = stack.pop();
if (secondPopValue === undefined) {
stack.push(firtPopValue);
} else {
secondPopValue *= 2;
stack.push(secondPopValue);
stack.push(firtPopValue);
}
} else if (str === "#") {
value = stack.pop();
stack.push(value * -1);
} else {
stack.push(Number(str));
}
}

for (element of stack) {
answer += element;
}

return answer;
}
10 changes: 10 additions & 0 deletions JustDevRae/Stack/reverse_string.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งค ๋ฐ˜๋ณต๋งˆ๋‹ค pop() ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ O(n) ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค!!
reverse()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”??

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function solution(my_string) {
var answer = "";
const string = [...my_string];

for (let i = 0; i < my_string.length; i++) {
answer += string.pop();
}

return answer;
}
16 changes: 16 additions & 0 deletions JustDevRae/Stack/valid_parentheses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function solution(s) {
const stack = [];
for (const c of s) {
if (c === "(") {
stack.push(c);
} else if (c === ")") {
if (stack.length === 0) {
continue;
} else {
stack.pop();
}
}
}

return stack.length === 0;
}