From 2c031495c5700900d5274e90259ae7b5df395878 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 19:45:17 +0900 Subject: [PATCH 01/52] =?UTF-8?q?=EB=B0=B0=EC=97=B4=20=EC=9E=90=EB=A5=B4?= =?UTF-8?q?=EA=B8=B0=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oh-chaeyeon/.gitkeep | 0 ...0\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" | 4 ++++ 2 files changed, 4 insertions(+) delete mode 100644 oh-chaeyeon/.gitkeep create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" diff --git a/oh-chaeyeon/.gitkeep b/oh-chaeyeon/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" new file mode 100644 index 0000000..1a6ac9f --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" @@ -0,0 +1,4 @@ +function solution(numbers, num1, num2) { + var answer = numbers.slice(num1, num2 + 1); + return answer; +} From b307f9513f384cbbb7ed797fce75579c15a94158 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 19:45:26 +0900 Subject: [PATCH 02/52] =?UTF-8?q?=EB=B0=B0=EC=97=B4=20=EC=9B=90=EC=86=8C?= =?UTF-8?q?=EC=9D=98=20=EA=B8=B8=EC=9D=B4=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...33\220\354\206\214\354\235\230_\352\270\270\354\235\264.js" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\233\220\354\206\214\354\235\230_\352\270\270\354\235\264.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\233\220\354\206\214\354\235\230_\352\270\270\354\235\264.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\233\220\354\206\214\354\235\230_\352\270\270\354\235\264.js" new file mode 100644 index 0000000..f4ec8ad --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\354\233\220\354\206\214\354\235\230_\352\270\270\354\235\264.js" @@ -0,0 +1,3 @@ +function solution(strlist) { + return strlist.map((str) => str.length); +} From 280b7948e998f638d412002be227ce9723010d52 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 19:45:41 +0900 Subject: [PATCH 03/52] =?UTF-8?q?=EB=B0=B0=EC=97=B4=20=ED=9A=8C=EC=A0=84?= =?UTF-8?q?=EC=8B=9C=ED=82=A4=EA=B8=B0=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\240\204\354\213\234\355\202\244\352\270\260.js" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\355\232\214\354\240\204\354\213\234\355\202\244\352\270\260.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\355\232\214\354\240\204\354\213\234\355\202\244\352\270\260.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\355\232\214\354\240\204\354\213\234\355\202\244\352\270\260.js" new file mode 100644 index 0000000..ad1b45f --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\260\260\354\227\264_\355\232\214\354\240\204\354\213\234\355\202\244\352\270\260.js" @@ -0,0 +1,10 @@ +function solution(numbers, direction) { + if (direction === "right") { + return [ + numbers[numbers.length - 1], + ...numbers.slice(0, numbers.length - 1), + ]; + } else if (direction === "left") { + return [...numbers.slice(1), numbers[0]]; + } +} From 2465ff2b0139305432c18f3b68711a6bcb5e0e52 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 19:46:02 +0900 Subject: [PATCH 04/52] =?UTF-8?q?=EC=A4=91=EB=B3=B5=EB=90=9C=20=EC=88=AB?= =?UTF-8?q?=EC=9E=90=20=EA=B0=9C=EC=88=98=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34_\354\210\253\354\236\220_\352\260\234\354\210\230.js" | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\244\221\353\263\265\353\220\234_\354\210\253\354\236\220_\352\260\234\354\210\230.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\244\221\353\263\265\353\220\234_\354\210\253\354\236\220_\352\260\234\354\210\230.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\244\221\353\263\265\353\220\234_\354\210\253\354\236\220_\352\260\234\354\210\230.js" new file mode 100644 index 0000000..6e41d12 --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\244\221\353\263\265\353\220\234_\354\210\253\354\236\220_\352\260\234\354\210\230.js" @@ -0,0 +1,6 @@ +function solution(array, n) { + var answer = array.reduce((count, num) => { + return num === n ? count + 1 : count; + }, 0); + return answer; +} From 9b120c8f0fd55d09dbe97ae4a404f5301c70b9bc Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 20:10:25 +0900 Subject: [PATCH 05/52] =?UTF-8?q?=EC=A0=9C=EC=9D=BC=20=EC=9E=91=EC=9D=80?= =?UTF-8?q?=20=EC=88=98=20=EC=A0=9C=EA=B1=B0=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\230_\354\240\234\352\261\260\355\225\230\352\270\260.js" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\240\234\354\235\274_\354\236\221\354\235\200_\354\210\230_\354\240\234\352\261\260\355\225\230\352\270\260.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\240\234\354\235\274_\354\236\221\354\235\200_\354\210\230_\354\240\234\352\261\260\355\225\230\352\270\260.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\240\234\354\235\274_\354\236\221\354\235\200_\354\210\230_\354\240\234\352\261\260\355\225\230\352\270\260.js" new file mode 100644 index 0000000..ed23df3 --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\354\240\234\354\235\274_\354\236\221\354\235\200_\354\210\230_\354\240\234\352\261\260\355\225\230\352\270\260.js" @@ -0,0 +1,5 @@ +function solution(arr) { + const min = Math.min(...arr); + var answer = arr.filter((num) => num !== min); + return answer.length === 0 ? [-1] : answer; +} From e54d44a702db28852b26538b91dbaebfbf08c8e3 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 20:10:37 +0900 Subject: [PATCH 06/52] =?UTF-8?q?=ED=96=89=EB=A0=AC=EC=9D=98=20=EB=8D=A7?= =?UTF-8?q?=EC=85=88=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\353\240\254\354\235\230_\353\215\247\354\205\210.js" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\353\215\247\354\205\210.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\353\215\247\354\205\210.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\353\215\247\354\205\210.js" new file mode 100644 index 0000000..ef51f3b --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\353\215\247\354\205\210.js" @@ -0,0 +1,8 @@ +function solution(arr1, arr2) { + var answer = arr1.map((row, i) => { + return row.map((num, j) => { + return num + arr2[i][j]; + }); + }); + return answer; +} From 7f618bf780f41b05a88b760dd8c50dc4b9007478 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 20:10:52 +0900 Subject: [PATCH 07/52] =?UTF-8?q?=EB=82=98=EB=88=84=EC=96=B4=20=EB=96=A8?= =?UTF-8?q?=EC=96=B4=EC=A7=80=EB=8A=94=20=EC=88=AB=EC=9E=90=20=EB=B0=B0?= =?UTF-8?q?=EC=97=B4=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...224_\354\210\253\354\236\220_\353\260\260\354\227\264.js" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\202\230\353\210\204\354\226\264_\353\226\250\354\226\264\354\247\200\353\212\224_\354\210\253\354\236\220_\353\260\260\354\227\264.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\202\230\353\210\204\354\226\264_\353\226\250\354\226\264\354\247\200\353\212\224_\354\210\253\354\236\220_\353\260\260\354\227\264.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\202\230\353\210\204\354\226\264_\353\226\250\354\226\264\354\247\200\353\212\224_\354\210\253\354\236\220_\353\260\260\354\227\264.js" new file mode 100644 index 0000000..a31726d --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\353\202\230\353\210\204\354\226\264_\353\226\250\354\226\264\354\247\200\353\212\224_\354\210\253\354\236\220_\353\260\260\354\227\264.js" @@ -0,0 +1,5 @@ +function solution(arr, divisor) { + var answer = arr.filter((num) => num % divisor === 0); + if (answer.length === 0) return [-1]; + return answer.sort((a, b) => a - b); +} From 121d553d7936cb1ab44ed08c39b3fc89bb30dae7 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 21:26:36 +0900 Subject: [PATCH 08/52] =?UTF-8?q?=ED=96=89=EB=A0=AC=EC=9D=98=20=EA=B3=B1?= =?UTF-8?q?=EC=85=88=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...254\354\235\230_\352\263\261\354\205\210.js" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\352\263\261\354\205\210.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\352\263\261\354\205\210.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\352\263\261\354\205\210.js" new file mode 100644 index 0000000..1d6cebc --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\355\226\211\353\240\254\354\235\230_\352\263\261\354\205\210.js" @@ -0,0 +1,17 @@ +function solution(arr1, arr2) { + const rowsA = arr1.length; + const colsA = arr1[0].length; + const colsB = arr2[0].length; + + const result = Array.from({ length: rowsA }, () => Array(colsB).fill(0)); + + // 행렬 곱셈 + for (let i = 0; i < rowsA; i++) { + for (let j = 0; j < colsB; j++) { + for (let k = 0; k < colsA; k++) { + result[i][j] += arr1[i][k] * arr2[k][j]; + } + } + } + return result; +} From 1c9229c5f079a90b2f5ccba57648e379a5508e3c Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 21:27:08 +0900 Subject: [PATCH 09/52] =?UTF-8?q?=EA=B5=90=EC=A0=90=EC=97=90=20=EB=B3=84?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4_\353\247\214\353\223\244\352\270\260.js" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\352\265\220\354\240\220\354\227\220_\353\263\204_\353\247\214\353\223\244\352\270\260.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\352\265\220\354\240\220\354\227\220_\353\263\204_\353\247\214\353\223\244\352\270\260.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\352\265\220\354\240\220\354\227\220_\353\263\204_\353\247\214\353\223\244\352\270\260.js" new file mode 100644 index 0000000..35d108a --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/\352\265\220\354\240\220\354\227\220_\353\263\204_\353\247\214\353\223\244\352\270\260.js" @@ -0,0 +1,39 @@ +function solution(line) { + const points = []; + + for (let i = 0; i < line.length; i++) { + for (let j = i + 1; j < line.length; j++) { + const [A1, B1, C1] = line[i]; + const [A2, B2, C2] = line[j]; + + const denominator = A1 * B2 - A2 * B1; + + if (denominator !== 0) { + const x = (B1 * C2 - B2 * C1) / denominator; + const y = (A2 * C1 - A1 * C2) / denominator; + + if (Number.isInteger(x) && Number.isInteger(y)) { + points.push([x, y]); + } + } + } + } + + const xs = points.map((point) => point[0]); + const ys = points.map((point) => point[1]); + + const minX = Math.min(...xs); + const maxX = Math.max(...xs); + const minY = Math.min(...ys); + const maxY = Math.max(...ys); + + const width = maxX - minX + 1; + const height = maxY - minY + 1; + const grid = Array.from({ length: height }, () => Array(width).fill(".")); + + for (const [x, y] of points) { + grid[maxY - y][x - minX] = "*"; + } + + return grid.map((row) => row.join("")); +} From 865c25746aa4d5f78e08a167e6b01d9a486e6117 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 2 Jan 2025 21:27:20 +0900 Subject: [PATCH 10/52] =?UTF-8?q?n^2=20=EB=B0=B0=EC=97=B4=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\227\264_\354\236\220\353\245\264\352\270\260.js" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/n^2_\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" diff --git "a/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/n^2_\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/n^2_\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" new file mode 100644 index 0000000..7d803a8 --- /dev/null +++ "b/oh-chaeyeon/1\354\243\274\354\260\250_\353\260\260\354\227\264/n^2_\353\260\260\354\227\264_\354\236\220\353\245\264\352\270\260.js" @@ -0,0 +1,9 @@ +function solution(n, left, right) { + const answer = []; + for (let k = left; k <= right; k++) { + const i = Math.floor(k / n); + const j = k % n; + answer.push(Math.max(i, j) + 1); + } + return answer; +} From ea88f07de1c44bc70d9f91e27809650bf2be1b02 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:09:57 +0900 Subject: [PATCH 11/52] =?UTF-8?q?String=20Reversal=20/=20=EA=B8=B0?= =?UTF-8?q?=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../String_Reversal.js" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Reversal.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Reversal.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Reversal.js" new file mode 100644 index 0000000..cae1e0c --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Reversal.js" @@ -0,0 +1,3 @@ +function solution(my_string) { + return my_string.split("").reverse().join(""); +} From 3f26859808e2143a96051c0d5e0cdaddeabb0c1c Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:10:13 +0900 Subject: [PATCH 12/52] =?UTF-8?q?Control=20Z=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Control_Z.js" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Control_Z.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Control_Z.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Control_Z.js" new file mode 100644 index 0000000..4086d55 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Control_Z.js" @@ -0,0 +1,14 @@ +function solution(s) { + const elements = s.split(" "); + let total = 0; + + for (let i = 0; i < elements.length; i++) { + if (elements[i] === "Z") { + total -= parseInt(elements[i - 1]); + } else { + total += parseInt(elements[i]); + } + } + + return total; +} From a8c82b3031f036f7c9d29322f1f452e290c8436a Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:10:31 +0900 Subject: [PATCH 13/52] =?UTF-8?q?Hate=20English=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hate_English.js" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Hate_English.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Hate_English.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Hate_English.js" new file mode 100644 index 0000000..245d676 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Hate_English.js" @@ -0,0 +1,22 @@ +function solution(numbers) { + return parseInt( + numbers.replace( + /zero|one|two|three|four|five|six|seven|eight|nine/g, + (match) => { + const numWords = { + zero: "0", + one: "1", + two: "2", + three: "3", + four: "4", + five: "5", + six: "6", + seven: "7", + eight: "8", + nine: "9", + }; + return numWords[match]; + } + ) + ); +} From 4a4f3f267702c21f4bb194d794fdec17a6811414 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:10:45 +0900 Subject: [PATCH 14/52] =?UTF-8?q?String=20Calculation=20/=20=EA=B8=B0?= =?UTF-8?q?=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../String_Calculation.js" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Calculation.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Calculation.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Calculation.js" new file mode 100644 index 0000000..50bd5cc --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/String_Calculation.js" @@ -0,0 +1,3 @@ +function solution(my_string) { + return eval(my_string); +} From d30a080545507aafb355477bccb9d658b3d71591 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:29:07 +0900 Subject: [PATCH 15/52] =?UTF-8?q?Crane=20Game=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Crane_Game.js" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Crane_Game.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Crane_Game.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Crane_Game.js" new file mode 100644 index 0000000..1c4f3f1 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Crane_Game.js" @@ -0,0 +1,25 @@ +function solution(board, moves) { + const basket = []; + let count = 0; + + for (let move of moves) { + const column = move - 1; + + for (let i = 0; i < board.length; i++) { + if (board[i][column] !== 0) { + const doll = board[i][column]; + board[i][column] = 0; + + if (basket[basket.length - 1] === doll) { + basket.pop(); + count += 2; + } else { + basket.push(doll); + } + break; + } + } + } + + return count; +} From a560deb1672bc9f655c4090021abcdd7edb07dea Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:29:17 +0900 Subject: [PATCH 16/52] =?UTF-8?q?Valid=20Parentheses=20/=20=EC=A4=91?= =?UTF-8?q?=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Valid_Parentheses.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Valid_Parentheses.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Valid_Parentheses.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Valid_Parentheses.js" new file mode 100644 index 0000000..1aee364 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Valid_Parentheses.js" @@ -0,0 +1,15 @@ +function solution(s) { + const stack = []; + + for (let char of s) { + if (char === "(") { + stack.push(char); + } else if (stack.length > 0) { + stack.pop(); + } else { + return false; + } + } + + return stack.length === 0; +} From 7dadd5d46b69bf1a168d83f534c6a3f55f72332d Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:29:33 +0900 Subject: [PATCH 17/52] =?UTF-8?q?Dart=20Game=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dart_Game.js" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Dart_Game.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Dart_Game.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Dart_Game.js" new file mode 100644 index 0000000..8b568f2 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Dart_Game.js" @@ -0,0 +1,24 @@ +function solution(dartResult) { + const stack = []; + let i = 0; + + while (i < dartResult.length) { + const isTen = dartResult[i] === "1" && dartResult[i + 1] === "0"; + let score = isTen ? 10 : parseInt(dartResult[i]); + i += isTen ? 2 : 1; + + const bonus = dartResult[i++]; + score **= bonus === "S" ? 1 : bonus === "D" ? 2 : 3; + + if (dartResult[i] === "*" || dartResult[i] === "#") { + score *= dartResult[i] === "*" ? 2 : -1; + if (dartResult[i++] === "*" && stack.length) { + stack[stack.length - 1] *= 2; + } + } + + stack.push(score); + } + + return stack.reduce((sum, cur) => sum + cur, 0); +} From b2fdfc604401db9470b1e9ec6be059137b3f16dc Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:56:39 +0900 Subject: [PATCH 18/52] =?UTF-8?q?Rotate=20Parentheses=20/=20=EC=8B=AC?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Rotate_Parentheses.js" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Rotate_Parentheses.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Rotate_Parentheses.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Rotate_Parentheses.js" new file mode 100644 index 0000000..599ac03 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Rotate_Parentheses.js" @@ -0,0 +1,25 @@ +function solution(s) { + let answer = 0; + for (let i = 0; i < s.length; i++) { + const rotated = s.slice(i) + s.slice(0, i); + if (isValid(rotated)) answer++; + } + return answer; +} + +function isValid(str) { + const stack = []; + for (let c of str) { + if ("([{".includes(c)) stack.push(c); + else if (!stack.length || !isPair(stack.pop(), c)) return false; + } + return stack.length === 0; +} + +function isPair(open, close) { + return ( + (open === "(" && close === ")") || + (open === "[" && close === "]") || + (open === "{" && close === "}") + ); +} From e00f4cd427891a1babde9136a588813b53f2ae3a Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:56:51 +0900 Subject: [PATCH 19/52] =?UTF-8?q?Stock=20Price=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Stock_Price.js" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Stock_Price.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Stock_Price.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Stock_Price.js" new file mode 100644 index 0000000..f5d8d0c --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Stock_Price.js" @@ -0,0 +1,18 @@ +function solution(prices) { + const answer = Array(prices.length).fill(0); + const stack = []; + + prices.forEach((price, i) => { + while (stack.length && prices[stack[stack.length - 1]] > price) { + const idx = stack.pop(); + answer[idx] = i - idx; + } + stack.push(i); + }); + + stack.forEach((idx) => { + answer[idx] = prices.length - 1 - idx; + }); + + return answer; +} From 9bd1415eae963d2ea2e8690c3823a9838177ee2e Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sun, 12 Jan 2025 02:56:58 +0900 Subject: [PATCH 20/52] =?UTF-8?q?Delivery=20Box=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Delivery_Box.js" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Delivery_Box.js" diff --git "a/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Delivery_Box.js" "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Delivery_Box.js" new file mode 100644 index 0000000..3d13dd4 --- /dev/null +++ "b/oh-chaeyeon/2\354\243\274\354\260\250_\354\212\244\355\203\235/Delivery_Box.js" @@ -0,0 +1,18 @@ +function solution(order) { + let stack = []; + let current = 1; + let count = 0; + + for (let box of order) { + while (current <= box) { + stack.push(current++); + } + if (stack.pop() === box) { + count++; + } else { + break; + } + } + + return count; +} From 8b3840d16c81c88cb710f6a865a10df175fcfe6c Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 16 Jan 2025 21:57:22 +0900 Subject: [PATCH 21/52] =?UTF-8?q?=EC=88=9C=EC=84=9C=EC=8C=8D=EC=9D=98=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Number_of_Ordered_Pairs.js" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Number_of_Ordered_Pairs.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Number_of_Ordered_Pairs.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Number_of_Ordered_Pairs.js" new file mode 100644 index 0000000..c7c3925 --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Number_of_Ordered_Pairs.js" @@ -0,0 +1,12 @@ +function solution(n) { + let num = 0; + for (let i = 1; i * i <= n; i++) { + if (n % i === 0) { + num += 2; + if (i * i === n) { + num--; + } + } + } + return num; +} From 071e7cc121643792888a36e2035cdd9ae19f5740 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 16 Jan 2025 21:57:37 +0900 Subject: [PATCH 22/52] =?UTF-8?q?=EC=A0=90=EC=9D=98=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20=EA=B5=AC=ED=95=98=EA=B8=B0=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Finding_the_Position_of_Points.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Finding_the_Position_of_Points.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Finding_the_Position_of_Points.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Finding_the_Position_of_Points.js" new file mode 100644 index 0000000..7ac4ac6 --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Finding_the_Position_of_Points.js" @@ -0,0 +1,15 @@ +function solution(dot) { + const x = dot[0]; + const y = dot[1]; + + switch (true) { + case x > 0 && y > 0: + return 1; + case x < 0 && y > 0: + return 2; + case x < 0 && y < 0: + return 3; + case x > 0 && y < 0: + return 4; + } +} From 5b021682591c21b524eaaba6711e514e42830a3b Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 16 Jan 2025 21:57:52 +0900 Subject: [PATCH 23/52] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=3F=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Login_Successful.js" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Login_Successful.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Login_Successful.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Login_Successful.js" new file mode 100644 index 0000000..19f24e8 --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Login_Successful.js" @@ -0,0 +1,11 @@ +function solution(id_pw, db) { + const [id, pw] = id_pw; + + for (const [dbId, dbPw] of db) { + if (dbId === id) { + return dbPw === pw ? "login" : "wrong pw"; + } + } + + return "fail"; +} From a358d28b65a10befcc8cad2aa7a441927b90935a Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 16 Jan 2025 21:58:04 +0900 Subject: [PATCH 24/52] =?UTF-8?q?=ED=8A=B9=EC=9D=B4=ED=95=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unusual_Sorting.js" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Unusual_Sorting.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Unusual_Sorting.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Unusual_Sorting.js" new file mode 100644 index 0000000..a334ff9 --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Unusual_Sorting.js" @@ -0,0 +1,11 @@ +function solution(numlist, n) { + return numlist.sort((a, b) => { + const A = Math.abs(a - n); + const B = Math.abs(b - n); + + if (A === B) { + return b - a; + } + return A - B; + }); +} From d0819a1126de1d8fde41e48fb44578b8ccdec0da Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sat, 18 Jan 2025 16:08:23 +0900 Subject: [PATCH 25/52] =?UTF-8?q?=EC=B9=B4=EB=93=9C=20=EB=AD=89=EC=B9=98?= =?UTF-8?q?=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Deck_of_Cards.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Deck_of_Cards.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Deck_of_Cards.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Deck_of_Cards.js" new file mode 100644 index 0000000..de4fdc3 --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Deck_of_Cards.js" @@ -0,0 +1,15 @@ +function solution(cards1, cards2, goal) { + const q1 = [...cards1]; + const q2 = [...cards2]; + + for (const word of goal) { + if (q1.length > 0 && q1[0] === word) { + q1.shift(); + } else if (q2.length > 0 && q2[0] === word) { + q2.shift(); + } else { + return "No"; + } + } + return "Yes"; +} From 420da51421a242a5e54ce7ff0f14fd157db80822 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sat, 18 Jan 2025 16:08:40 +0900 Subject: [PATCH 26/52] =?UTF-8?q?=EA=B3=B5=EC=9B=90=20=EC=82=B0=EC=B1=85?= =?UTF-8?q?=20=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Walking_in_the_Park.js" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Walking_in_the_Park.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Walking_in_the_Park.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Walking_in_the_Park.js" new file mode 100644 index 0000000..ea6280f --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Walking_in_the_Park.js" @@ -0,0 +1,44 @@ +function solution(park, routes) { + const directions = { N: [-1, 0], S: [1, 0], W: [0, -1], E: [0, 1] }; + let x, y; + + for (let i = 0; i < park.length; i++) { + const j = park[i].indexOf("S"); + if (j !== -1) { + x = i; + y = j; + break; + } + } + + for (const route of routes) { + const [direction, distanceStr] = route.split(" "); + const distance = parseInt(distanceStr); + const [dx, dy] = directions[direction]; + + let canMove = true; + + for (let step = 1; step <= distance; step++) { + const newX = x + dx * step; + const newY = y + dy * step; + + if ( + newX < 0 || + newX >= park.length || + newY < 0 || + newY >= park[0].length || + park[newX][newY] === "X" + ) { + canMove = false; + break; + } + } + + if (canMove) { + x += dx * distance; + y += dy * distance; + } + } + + return [x, y]; +} From f4bc768a124c98897c550ade69f2935483647b68 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Sat, 18 Jan 2025 16:08:48 +0900 Subject: [PATCH 27/52] =?UTF-8?q?=ED=96=84=EB=B2=84=EA=B1=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Making_a_Hamburger.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Making_a_Hamburger.js" diff --git "a/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Making_a_Hamburger.js" "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Making_a_Hamburger.js" new file mode 100644 index 0000000..cb2041c --- /dev/null +++ "b/oh-chaeyeon/3\354\243\274\354\260\250_\355\201\220/Making_a_Hamburger.js" @@ -0,0 +1,15 @@ +function solution(ingredient) { + const q = []; + let count = 0; + + for (const item of ingredient) { + q.push(item); + + if (q.length >= 4 && q.slice(-4).join("") === "1231") { + q.splice(-4); + count++; + } + } + + return count; +} From 5815b69ea06c049428e3488f8deb33be09047cdb Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:08:02 +0900 Subject: [PATCH 28/52] =?UTF-8?q?=EB=AA=A8=EC=8A=A4=EB=B6=80=ED=98=B81=20/?= =?UTF-8?q?=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\212\244\353\266\200\355\230\2701.js" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\252\250\354\212\244\353\266\200\355\230\2701.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\252\250\354\212\244\353\266\200\355\230\2701.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\252\250\354\212\244\353\266\200\355\230\2701.js" new file mode 100644 index 0000000..ed2b352 --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\252\250\354\212\244\353\266\200\355\230\2701.js" @@ -0,0 +1,34 @@ +function solution(letter) { + const morse = { + ".-": "a", + "-...": "b", + "-.-.": "c", + "-..": "d", + ".": "e", + "..-.": "f", + "--.": "g", + "....": "h", + "..": "i", + ".---": "j", + "-.-": "k", + ".-..": "l", + "--": "m", + "-.": "n", + "---": "o", + ".--.": "p", + "--.-": "q", + ".-.": "r", + "...": "s", + "-": "t", + "..-": "u", + "...-": "v", + ".--": "w", + "-..-": "x", + "-.--": "y", + "--..": "z", + }; + return letter + .split(" ") + .map((code) => morse[code]) + .join(""); +} From 474e84252a8ddf4d0b4b371a098b05f9bb12738e Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:08:24 +0900 Subject: [PATCH 29/52] =?UTF-8?q?A=EB=A1=9C=20B=EB=A7=8C=EB=93=A4=EA=B8=B0?= =?UTF-8?q?=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../A\353\241\234_B_\353\247\214\353\223\244\352\270\260.js" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/A\353\241\234_B_\353\247\214\353\223\244\352\270\260.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/A\353\241\234_B_\353\247\214\353\223\244\352\270\260.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/A\353\241\234_B_\353\247\214\353\223\244\352\270\260.js" new file mode 100644 index 0000000..1733e64 --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/A\353\241\234_B_\353\247\214\353\223\244\352\270\260.js" @@ -0,0 +1,5 @@ +function solution(before, after) { + return before.split("").sort().join("") === after.split("").sort().join("") + ? 1 + : 0; +} From c72670830243478c4691a924a5b27b8817f7266b Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:08:39 +0900 Subject: [PATCH 30/52] =?UTF-8?q?=EC=A7=84=EB=A1=9C=20=EC=88=9C=EC=84=9C?= =?UTF-8?q?=20=EC=A0=95=ED=95=98=EA=B8=B0=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\234\354\204\234_\354\240\225\355\225\230\352\270\260.js" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\247\204\353\241\234_\354\210\234\354\204\234_\354\240\225\355\225\230\352\270\260.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\247\204\353\241\234_\354\210\234\354\204\234_\354\240\225\355\225\230\352\270\260.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\247\204\353\241\234_\354\210\234\354\204\234_\354\240\225\355\225\230\352\270\260.js" new file mode 100644 index 0000000..9cf5f17 --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\247\204\353\241\234_\354\210\234\354\204\234_\354\240\225\355\225\230\352\270\260.js" @@ -0,0 +1,5 @@ +function solution(emergency) { + return emergency.map( + (e) => [...emergency].sort((a, b) => b - a).indexOf(e) + 1 + ); +} From e30e7d694da55cde58b8e23f42d5d5978644f9b1 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:09:11 +0900 Subject: [PATCH 31/52] =?UTF-8?q?=EB=93=B1=EC=88=98=20=EB=A7=A4=EA=B8=B0?= =?UTF-8?q?=EA=B8=B0=20/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...261\354\210\230_\353\247\244\352\270\260\352\270\260.js" | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\223\261\354\210\230_\353\247\244\352\270\260\352\270\260.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\223\261\354\210\230_\353\247\244\352\270\260\352\270\260.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\223\261\354\210\230_\353\247\244\352\270\260\352\270\260.js" new file mode 100644 index 0000000..25ca70a --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\353\223\261\354\210\230_\353\247\244\352\270\260\352\270\260.js" @@ -0,0 +1,6 @@ +function solution(score) { + const averages = score.map((s) => (s[0] + s[1]) / 2); + const sortedAverages = [...averages].sort((a, b) => b - a); + + return averages.map((avg) => sortedAverages.indexOf(avg) + 1); +} From a8d94b17e77b781a213b563367bd584782e1761a Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:09:37 +0900 Subject: [PATCH 32/52] =?UTF-8?q?=EC=99=84=EC=A3=BC=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=9C=20=EC=84=A0=EC=88=98=20/=20=EC=A4=91?= =?UTF-8?q?=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\252\273\355\225\234_\354\204\240\354\210\230.js" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\231\204\354\243\274\355\225\230\354\247\200_\353\252\273\355\225\234_\354\204\240\354\210\230.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\231\204\354\243\274\355\225\230\354\247\200_\353\252\273\355\225\234_\354\204\240\354\210\230.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\231\204\354\243\274\355\225\230\354\247\200_\353\252\273\355\225\234_\354\204\240\354\210\230.js" new file mode 100644 index 0000000..2693d05 --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\231\204\354\243\274\355\225\230\354\247\200_\353\252\273\355\225\234_\354\204\240\354\210\230.js" @@ -0,0 +1,12 @@ +function solution(participant, completion) { + const count = participant.reduce((acc, name) => { + acc[name] = (acc[name] || 0) + 1; + return acc; + }, {}); + + completion.forEach((name) => { + count[name]--; + }); + + return Object.keys(count).find((name) => count[name] > 0); +} From e27c3a986ed116764718dcc31f7f99fe07c0343d Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:10:03 +0900 Subject: [PATCH 33/52] =?UTF-8?q?=ED=8F=AC=EC=BC=93=EB=AA=AC=20/=20?= =?UTF-8?q?=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\217\260\354\274\223\353\252\254.js" | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\217\260\354\274\223\353\252\254.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\217\260\354\274\223\353\252\254.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\217\260\354\274\223\353\252\254.js" new file mode 100644 index 0000000..ed4042a --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\217\260\354\274\223\353\252\254.js" @@ -0,0 +1,6 @@ +function solution(nums) { + const newNum = [...new Set(nums)]; + const selection = nums.length / 2; + + return Math.min(newNum.length, selection); +} From d2301ffc175f28977f010c7380f0dd5eab96c207 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:10:24 +0900 Subject: [PATCH 34/52] =?UTF-8?q?=EC=B6=94=EC=96=B5=20=EC=A0=90=EC=88=98?= =?UTF-8?q?=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\266\224\354\226\265_\354\240\220\354\210\230.js" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\266\224\354\226\265_\354\240\220\354\210\230.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\266\224\354\226\265_\354\240\220\354\210\230.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\266\224\354\226\265_\354\240\220\354\210\230.js" new file mode 100644 index 0000000..019bd7c --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\266\224\354\226\265_\354\240\220\354\210\230.js" @@ -0,0 +1,8 @@ +function solution(name, yearning, photo) { + return photo.map((p) => + p.reduce((sum, person) => { + const index = name.indexOf(person); + return sum + (index !== -1 ? yearning[index] : 0); + }, 0) + ); +} From 16b93e3af546952e4ae1cbe072c491d9ba7b87c3 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:11:02 +0900 Subject: [PATCH 35/52] =?UTF-8?q?=ED=95=A0=EC=9D=B8=20=ED=96=89=EC=82=AC?= =?UTF-8?q?=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\270_\355\226\211\354\202\254.js" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\225\240\354\235\270_\355\226\211\354\202\254.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\225\240\354\235\270_\355\226\211\354\202\254.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\225\240\354\235\270_\355\226\211\354\202\254.js" new file mode 100644 index 0000000..9751c1d --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\355\225\240\354\235\270_\355\226\211\354\202\254.js" @@ -0,0 +1,24 @@ +function solution(want, number, discount) { + const required = {}; + want.forEach((item, index) => { + required[item] = number[index]; + }); + + let day = 0; + + for (let i = 0; i <= discount.length - 10; i++) { + const current = {}; + + for (let j = i; j < i + 10; j++) { + current[discount[j]] = (current[discount[j]] || 0) + 1; + } + + const isValid = want.every( + (item) => (current[item] || 0) >= required[item] + ); + + if (isValid) day++; + } + + return day; +} From 4b3f8ee30fa56e6baeac766f32cea27ae368c577 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 27 Jan 2025 21:11:25 +0900 Subject: [PATCH 36/52] =?UTF-8?q?=20=EC=98=A4=ED=94=88=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=20/=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...10\354\261\204\355\214\205\353\260\251.js" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.js" diff --git "a/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.js" "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.js" new file mode 100644 index 0000000..95e6713 --- /dev/null +++ "b/oh-chaeyeon/4\354\243\274\354\260\250_\355\225\264\354\213\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.js" @@ -0,0 +1,22 @@ +function solution(record) { + const nicknames = {}; + const result = []; + + record.forEach((entry) => { + const [action, userId, nickname] = entry.split(" "); + if (action !== "Leave") { + nicknames[userId] = nickname; + } + }); + + record.forEach((entry) => { + const [action, userId] = entry.split(" "); + if (action === "Enter") { + result.push(`${nicknames[userId]}님이 들어왔습니다.`); + } else if (action === "Leave") { + result.push(`${nicknames[userId]}님이 나갔습니다.`); + } + }); + + return result; +} From eba0569a7e00ec4a0206ed2894a286409945a186 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:24:41 +0900 Subject: [PATCH 37/52] =?UTF-8?q?Maximum=20Depth=20of=20Binary=20Tree=20/?= =?UTF-8?q?=20=EC=B4=88=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Maximum_Depth_of_Binary_Tree.js" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Maximum_Depth_of_Binary_Tree.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Maximum_Depth_of_Binary_Tree.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Maximum_Depth_of_Binary_Tree.js" new file mode 100644 index 0000000..e676b5c --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Maximum_Depth_of_Binary_Tree.js" @@ -0,0 +1,22 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {number} + */ +var maxDepth = function (root) { + if (root === null) { + return 0; + } + + let leftDepth = maxDepth(root.left); + let rightDepth = maxDepth(root.right); + + return Math.max(leftDepth, rightDepth) + 1; +}; From d4d18404650fcb5d3c6414912084e8826148feec Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:24:59 +0900 Subject: [PATCH 38/52] =?UTF-8?q?Binary=20Tree=20Inorder=20Traversal=20/?= =?UTF-8?q?=20=EC=B4=88=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Binary_Tree_Inorder_Traversal.js" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Inorder_Traversal.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Inorder_Traversal.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Inorder_Traversal.js" new file mode 100644 index 0000000..57bec16 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Inorder_Traversal.js" @@ -0,0 +1,23 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {number[]} + */ +var inorderTraversal = function (root) { + const result = []; + function traverse(node) { + if (!node) return; + traverse(node.left); + result.push(node.val); + traverse(node.right); + } + traverse(root); + return result; +}; From 1602133cb99f6875fd27d5a7bec99dacfde451cc Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:25:15 +0900 Subject: [PATCH 39/52] =?UTF-8?q?Same=20Tree=20/=20=EC=B4=88=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Same_Tree.js" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Same_Tree.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Same_Tree.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Same_Tree.js" new file mode 100644 index 0000000..37b5b14 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Same_Tree.js" @@ -0,0 +1,28 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} p + * @param {TreeNode} q + * @return {boolean} + */ +var isSameTree = function (p, q) { + if (p === null && q === null) { + return true; + } + + if (p === null || q === null) { + return false; + } + + if (p.val !== q.val) { + return false; + } + + return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); +}; From 648f832d0dd494354162b1f08d0218d5629b5f86 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:25:46 +0900 Subject: [PATCH 40/52] =?UTF-8?q?Invert=20Binary=20Tree=20/=20=EC=B4=88?= =?UTF-8?q?=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Invert_Binary_Tree.js" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Invert_Binary_Tree.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Invert_Binary_Tree.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Invert_Binary_Tree.js" new file mode 100644 index 0000000..9cff07e --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Invert_Binary_Tree.js" @@ -0,0 +1,26 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {TreeNode} + */ +var invertTree = function (root) { + if (root === null) { + return null; + } + + let temp = root.left; + root.left = root.right; + root.right = temp; + + invertTree(root.left); + invertTree(root.right); + + return root; +}; From 94cfe6d1f3332324901945d4afc67041abe4624b Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:27:49 +0900 Subject: [PATCH 41/52] =?UTF-8?q?Binary=20Tree=20Level=20Order=20Traversal?= =?UTF-8?q?=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Binary_Tree_Level_Order_Traversal.js" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Level_Order_Traversal.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Level_Order_Traversal.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Level_Order_Traversal.js" new file mode 100644 index 0000000..b0c7905 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Level_Order_Traversal.js" @@ -0,0 +1,26 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {number[][]} + */ +var levelOrder = function (root) { + const result = []; + + function traverse(node, level) { + if (!node) return; + if (!result[level]) result[level] = []; + result[level].push(node.val); + traverse(node.left, level + 1); + traverse(node.right, level + 1); + } + + traverse(root, 0); + return result; +}; From 98fa4504e1778737a3e41716399d98f0a3ac7fe8 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:28:00 +0900 Subject: [PATCH 42/52] =?UTF-8?q?Validate=20Binary=20Search=20Tree=20/=20?= =?UTF-8?q?=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Validate_Binary_Search_Tree.js" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Validate_Binary_Search_Tree.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Validate_Binary_Search_Tree.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Validate_Binary_Search_Tree.js" new file mode 100644 index 0000000..8639543 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Validate_Binary_Search_Tree.js" @@ -0,0 +1,24 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {boolean} + */ +var isValidBST = function (root) { + function validate(node, lower, upper) { + if (!node) return true; + + const val = node.val; + if (val <= lower || val >= upper) return false; + + return validate(node.left, lower, val) && validate(node.right, val, upper); + } + + return validate(root, -Infinity, Infinity); +}; From c2ef4b360c0d3712cd2ff2a244147be7267d33f6 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:28:13 +0900 Subject: [PATCH 43/52] =?UTF-8?q?Construct=20Binary=20Tree=20from=20Preord?= =?UTF-8?q?er=20and=20Inorder=20Traversal=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ee_from_Preorder_and_Inorder_Traversal.js" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js" new file mode 100644 index 0000000..50b3860 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js" @@ -0,0 +1,38 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {number[]} preorder + * @param {number[]} inorder + * @return {TreeNode} + */ +var buildTree = function (preorder, inorder) { + const inorderMap = new Map(); + inorder.forEach((val, idx) => inorderMap.set(val, idx)); + + function build(preStart, preEnd, inStart, inEnd) { + if (preStart > preEnd || inStart > inEnd) return null; + + const rootVal = preorder[preStart]; + const root = new TreeNode(rootVal); + const inRootIndex = inorderMap.get(rootVal); + const leftSize = inRootIndex - inStart; + + root.left = build( + preStart + 1, + preStart + leftSize, + inStart, + inRootIndex - 1 + ); + root.right = build(preStart + leftSize + 1, preEnd, inRootIndex + 1, inEnd); + + return root; + } + + return build(0, preorder.length - 1, 0, inorder.length - 1); +}; From 8228c60b9a0727d8067ff41bce5f24e933f9d140 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:29:42 +0900 Subject: [PATCH 44/52] =?UTF-8?q?=EC=9D=B4=EC=A7=84=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=20=EB=B0=98=EB=B3=B5=ED=95=98=EA=B8=B0=20/=20=EC=8B=AC?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\230\353\263\265\355\225\230\352\270\260.js" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/\354\235\264\354\247\204_\353\263\200\355\231\230_\353\260\230\353\263\265\355\225\230\352\270\260.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/\354\235\264\354\247\204_\353\263\200\355\231\230_\353\260\230\353\263\265\355\225\230\352\270\260.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/\354\235\264\354\247\204_\353\263\200\355\231\230_\353\260\230\353\263\265\355\225\230\352\270\260.js" new file mode 100644 index 0000000..bb632c8 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/\354\235\264\354\247\204_\353\263\200\355\231\230_\353\260\230\353\263\265\355\225\230\352\270\260.js" @@ -0,0 +1,17 @@ +function solution(s) { + let count = 0; + let removed = 0; + + while (s !== "1") { + const originalLength = s.length; + const newStr = s + .split("") + .filter((char) => char === "1") + .join(""); + removed += originalLength - newStr.length; + s = newStr.length.toString(2); + count++; + } + + return [count, removed]; +} From de828daa95df50b93b9749a40b125da08430151f Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Mon, 10 Feb 2025 17:30:02 +0900 Subject: [PATCH 45/52] =?UTF-8?q?Binary=20Tree=20Maximum=20Path=20Sum=20/?= =?UTF-8?q?=20=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Binary_Tree_Maximum_Path_Sum.js" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Maximum_Path_Sum.js" diff --git "a/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Maximum_Path_Sum.js" "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Maximum_Path_Sum.js" new file mode 100644 index 0000000..12f7554 --- /dev/null +++ "b/oh-chaeyeon/5\354\243\274\354\260\250_\355\212\270\353\246\254/Binary_Tree_Maximum_Path_Sum.js" @@ -0,0 +1,31 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {number} + */ +var maxPathSum = function (root) { + let maxSum = -Infinity; + + function dfs(node) { + if (!node) return 0; + + const left = Math.max(dfs(node.left), 0); + const right = Math.max(dfs(node.right), 0); + + const currentSum = node.val + left + right; + + maxSum = Math.max(maxSum, currentSum); + + return node.val + Math.max(left, right); + } + + dfs(root); + return maxSum; +}; From 7817495332bbc291f73318e567a924b0e2e0951a Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:13:41 +0900 Subject: [PATCH 46/52] =?UTF-8?q?Find=20the=20Town=20Judge=20/=20=EA=B8=B0?= =?UTF-8?q?=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Find_the_Town_Judge.js" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_the_Town_Judge.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_the_Town_Judge.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_the_Town_Judge.js" new file mode 100644 index 0000000..27f697c --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_the_Town_Judge.js" @@ -0,0 +1,21 @@ +/** + * @param {number} n + * @param {number[][]} trust + * @return {number} + */ +var findJudge = function (n, trust) { + const trustCount = new Array(n + 1).fill(0); + + for (const [a, b] of trust) { + trustCount[a]--; + trustCount[b]++; + } + + for (let i = 1; i <= n; i++) { + if (trustCount[i] === n - 1) { + return i; + } + } + + return -1; +}; From 8dcfb92d66fdd9ad9f12bf9412e8293124a35730 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:13:54 +0900 Subject: [PATCH 47/52] =?UTF-8?q?Find=20if=20Path=20Exists=20in=20Graph=20?= =?UTF-8?q?/=20=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Find_if_Path_Exists_in_Graph.js" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_if_Path_Exists_in_Graph.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_if_Path_Exists_in_Graph.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_if_Path_Exists_in_Graph.js" new file mode 100644 index 0000000..f7c4fea --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_if_Path_Exists_in_Graph.js" @@ -0,0 +1,32 @@ +/** + * @param {number} n + * @param {number[][]} edges + * @param {number} source + * @param {number} destination + * @return {boolean} + */ +var validPath = function (n, edges, source, destination) { + const graph = Array.from({ length: n }, () => []); + + edges.forEach(([u, v]) => { + graph[u].push(v); + graph[v].push(u); + }); + + const visited = new Set(); + + const dfs = (node) => { + if (node === destination) return true; + visited.add(node); + + for (const neighbor of graph[node]) { + if (!visited.has(neighbor) && dfs(neighbor)) { + return true; + } + } + + return false; + }; + + return dfs(source); +}; From 4cf5fdf6adcae52392ca81aabd0aa6ab7672df67 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:15:04 +0900 Subject: [PATCH 48/52] =?UTF-8?q?Find=20Center=20of=20Star=20Graph=20/=20?= =?UTF-8?q?=EA=B8=B0=EC=B4=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Find_Center_of_Star_Graph.js" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_Center_of_Star_Graph.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_Center_of_Star_Graph.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_Center_of_Star_Graph.js" new file mode 100644 index 0000000..6841e5c --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/Find_Center_of_Star_Graph.js" @@ -0,0 +1,9 @@ +/** + * @param {number[][]} edges + * @return {number} + */ +var findCenter = function (edges) { + return edges[0][0] === edges[1][0] || edges[0][0] === edges[1][1] + ? edges[0][0] + : edges[0][1]; +}; From 9f47b9b71a3e3d91d709d0faca997962bfef4aad Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:15:20 +0900 Subject: [PATCH 49/52] =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EB=A7=B5=20?= =?UTF-8?q?=EC=B5=9C=EB=8B=A8=EA=B1=B0=EB=A6=AC=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\213\250\352\261\260\353\246\254.js" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254.js" new file mode 100644 index 0000000..e702c95 --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254.js" @@ -0,0 +1,45 @@ +function solution(maps) { + const n = maps.length; + const m = maps[0].length; + const directions = [ + [1, 0], + [-1, 0], + [0, 1], + [0, -1], + ]; + const queue = [[0, 0]]; + const visited = Array.from({ length: n }, () => Array(m).fill(false)); + visited[0][0] = true; + let count = 1; + + while (queue.length > 0) { + const size = queue.length; + for (let i = 0; i < size; i++) { + const [x, y] = queue.shift(); + + if (x === n - 1 && y === m - 1) { + return count; + } + + for (const [dx, dy] of directions) { + const nx = x + dx; + const ny = y + dy; + + if ( + nx >= 0 && + ny >= 0 && + nx < n && + ny < m && + maps[nx][ny] === 1 && + !visited[nx][ny] + ) { + visited[nx][ny] = true; + queue.push([nx, ny]); + } + } + } + count++; + } + + return -1; +} From ddfb81f6f4e9a860eb856f584091fb6a65e6c11e Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:15:35 +0900 Subject: [PATCH 50/52] =?UTF-8?q?=ED=83=80=EA=B2=9F=20=EB=84=98=EB=B2=84?= =?UTF-8?q?=20/=20=EC=A4=91=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\354\274\223_\353\204\230\353\262\204.js" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\355\203\200\354\274\223_\353\204\230\353\262\204.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\355\203\200\354\274\223_\353\204\230\353\262\204.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\355\203\200\354\274\223_\353\204\230\353\262\204.js" new file mode 100644 index 0000000..2496c77 --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\355\203\200\354\274\223_\353\204\230\353\262\204.js" @@ -0,0 +1,18 @@ +function solution(numbers, target) { + const dp = new Map(); + dp.set(0, 1); + + for (const number of numbers) { + const nextDp = new Map(); + for (const [sum, count] of dp) { + nextDp.set(sum + number, (nextDp.get(sum + number) || 0) + count); + nextDp.set(sum - number, (nextDp.get(sum - number) || 0) + count); + } + dp.clear(); + for (const [sum, count] of nextDp) { + dp.set(sum, count); + } + } + + return dp.get(target) || 0; +} From 0016a9af5c555f4bd9575cb546d8dbbe7e731ace Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:15:49 +0900 Subject: [PATCH 51/52] =?UTF-8?q?=EC=A0=84=EB=A0=A5=EB=A7=9D=EC=9D=84=20?= =?UTF-8?q?=EB=91=98=EB=A1=9C=20=EB=82=98=EB=88=84=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=8B=AC=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4_\353\202\230\353\210\204\352\270\260.js" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\354\240\204\353\240\245\353\247\235\354\235\204_\353\217\214\353\241\234_\353\202\230\353\210\204\352\270\260.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\354\240\204\353\240\245\353\247\235\354\235\204_\353\217\214\353\241\234_\353\202\230\353\210\204\352\270\260.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\354\240\204\353\240\245\353\247\235\354\235\204_\353\217\214\353\241\234_\353\202\230\353\210\204\352\270\260.js" new file mode 100644 index 0000000..4b26735 --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\354\240\204\353\240\245\353\247\235\354\235\204_\353\217\214\353\241\234_\353\202\230\353\210\204\352\270\260.js" @@ -0,0 +1,33 @@ +function solution(n, wires) { + const graph = Array.from({ length: n + 1 }, () => []); + + for (const [v1, v2] of wires) { + graph[v1].push(v2); + graph[v2].push(v1); + } + + let minDifference = Number.MAX_VALUE; + + const dfs = (node, visited) => { + let count = 1; + visited[node] = true; + + for (const neighbor of graph[node]) { + if (!visited[neighbor]) { + count += dfs(neighbor, visited); + } + } + + return count; + }; + + for (const [v1, v2] of wires) { + const visited = Array(n + 1).fill(false); + visited[v1] = true; + const count = dfs(v2, visited); + const difference = Math.abs(count - (n - count)); + minDifference = Math.min(minDifference, difference); + } + + return minDifference; +} From 4e37e37110f2b559050a1197781298f6f96cdc55 Mon Sep 17 00:00:00 2001 From: oh-chaeyeon Date: Thu, 20 Feb 2025 21:15:58 +0900 Subject: [PATCH 52/52] =?UTF-8?q?=EB=B0=B0=EB=8B=AC=20/=20=EC=8B=AC?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\260\353\213\254.js" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\353\260\260\353\213\254.js" diff --git "a/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\353\260\260\353\213\254.js" "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\353\260\260\353\213\254.js" new file mode 100644 index 0000000..01a4c65 --- /dev/null +++ "b/oh-chaeyeon/7\354\243\274\354\260\250_\352\267\270\353\236\230\355\224\204/\353\260\260\353\213\254.js" @@ -0,0 +1,31 @@ +function solution(N, road, K) { + const graph = Array.from({ length: N + 1 }, () => []); + + for (const [a, b, c] of road) { + graph[a].push([b, c]); + graph[b].push([a, c]); + } + + const distances = Array(N + 1).fill(Infinity); + distances[1] = 0; + const priorityQueue = [[0, 1]]; + + while (priorityQueue.length > 0) { + const [currentDistance, currentNode] = priorityQueue.shift(); + + if (currentDistance > distances[currentNode]) { + continue; + } + + for (const [neighbor, time] of graph[currentNode]) { + const newDistance = currentDistance + time; + if (newDistance < distances[neighbor]) { + distances[neighbor] = newDistance; + priorityQueue.push([newDistance, neighbor]); + priorityQueue.sort((a, b) => a[0] - b[0]); + } + } + } + + return distances.filter((distance) => distance <= K).length; +}