From 7acd8f711b88f81cfe713798ef99b4354ebd1aa0 Mon Sep 17 00:00:00 2001 From: jdy8739 Date: Tue, 14 Jan 2025 23:36:43 +0900 Subject: [PATCH 1/4] Valid Parentheses solution --- valid-parentheses/jdy8739.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 valid-parentheses/jdy8739.js diff --git a/valid-parentheses/jdy8739.js b/valid-parentheses/jdy8739.js new file mode 100644 index 000000000..194fbc83f --- /dev/null +++ b/valid-parentheses/jdy8739.js @@ -0,0 +1,30 @@ +/** + * @param {string} s + * @return {boolean} + */ +var isValid = function(s) { + const stack = []; + + for (let i=0; i Date: Wed, 15 Jan 2025 00:01:06 +0900 Subject: [PATCH 2/4] container-with-most-water solution --- container-with-most-water/jdy8739.js | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 container-with-most-water/jdy8739.js diff --git a/container-with-most-water/jdy8739.js b/container-with-most-water/jdy8739.js new file mode 100644 index 000000000..2e6935370 --- /dev/null +++ b/container-with-most-water/jdy8739.js @@ -0,0 +1,32 @@ +/** + * @param {number[]} height + * @return {number} + */ +var maxArea = function(height) { + let max = 0; + + let startIdx = 0; + let endIdx = height.length - 1; + + while (startIdx < endIdx) { + const start = height[startIdx]; + const end = height[endIdx]; + + const gap = endIdx - startIdx; + const min = Math.min(start, end); + + const area = gap * min; + + max = Math.max(max, area); + + if (start < end) startIdx++; + else endIdx--; + } + + return max; +}; + +// 시간복잡도 O(n) +// n은 주어진 배열(height)의 길이 + + From ea83802ab7d1dbefc753783e207f12866b64c6cd Mon Sep 17 00:00:00 2001 From: jdy8739 Date: Sat, 18 Jan 2025 13:12:44 +0900 Subject: [PATCH 3/4] SPIRAL-MATRIX solution --- spiral-matrix/jdy8739.js | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 spiral-matrix/jdy8739.js diff --git a/spiral-matrix/jdy8739.js b/spiral-matrix/jdy8739.js new file mode 100644 index 000000000..dda2bda7c --- /dev/null +++ b/spiral-matrix/jdy8739.js @@ -0,0 +1,47 @@ +/** + * @param {number[][]} matrix + * @return {number[]} + */ +var spiralOrder = function(matrix) { + let top = 0; + let left = 0; + let bottom = matrix.length - 1; + let right = matrix[0].length - 1; + + const answer = []; + + while (top <= bottom && left <= right) { + for (let i = left; i <= right; i++) { + answer.push(matrix[top][i]); + } + top++; + + if (top > bottom) { + break; + } + + for (let j = top; j <= bottom; j++) { + answer.push(matrix[j][right]); + } + right--; + + if (left > right) { + break; + } + + for (let k = right; k >= left; k--) { + answer.push(matrix[bottom][k]); + } + bottom--; + + for (let l = bottom; l >= top; l--) { + answer.push(matrix[l][left]); + } + left++; + } + + return answer; +}; + +// 시간 복잡도 O(m * n) +// 공간 복잡도 O(1) \ No newline at end of file From 13a6d25a95821b157621101698790fceedd87591 Mon Sep 17 00:00:00 2001 From: jdy8739 Date: Sat, 18 Jan 2025 13:16:23 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20SPIRAL-MATRIX=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=EC=97=90=20=EB=9D=BC=EC=9D=B8=EC=97=AC?= =?UTF-8?q?=EB=B0=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spiral-matrix/jdy8739.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spiral-matrix/jdy8739.js b/spiral-matrix/jdy8739.js index dda2bda7c..136bb348c 100644 --- a/spiral-matrix/jdy8739.js +++ b/spiral-matrix/jdy8739.js @@ -44,4 +44,6 @@ var spiralOrder = function(matrix) { }; // 시간 복잡도 O(m * n) -// 공간 복잡도 O(1) \ No newline at end of file +// 공간 복잡도 O(1) + +