From 2e7b0ffcba6b5090622090fd404d7cee16171f23 Mon Sep 17 00:00:00 2001 From: JangAyeon Date: Fri, 21 Nov 2025 07:35:18 +0900 Subject: [PATCH 1/5] solve valid anagram --- valid-anagram/JangAyeon.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 valid-anagram/JangAyeon.js diff --git a/valid-anagram/JangAyeon.js b/valid-anagram/JangAyeon.js new file mode 100644 index 0000000000..085238da5e --- /dev/null +++ b/valid-anagram/JangAyeon.js @@ -0,0 +1,31 @@ +/** + * @param {string} s + * @param {string} t + * @return {boolean} + */ +var isAnagram = function (s, t) { + const sCounter = new Map(); + for (let e of s) { + // console.log(e) + const value = sCounter.has(e) ? sCounter.get(e) + 1 : 1; + sCounter.set(e, value); + } + console.log(sCounter); + + for (let e of t) { + if (!sCounter.has(e)) { + return false; + } + const value = sCounter.get(e); + if (value - 1 < 0) { + return false; + } + if (value - 1 == 0) { + sCounter.delete(e); + } else { + sCounter.set(e, value - 1); + } + } + const notAllused = [...sCounter.keys()].length; + return !notAllused; +}; From 834ac4ee5cfde1d3f7e350765249e5b6854a7850 Mon Sep 17 00:00:00 2001 From: JangAyeon Date: Fri, 21 Nov 2025 07:38:32 +0900 Subject: [PATCH 2/5] solve climbing stair --- climbing-stairs/JangAyeon.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 climbing-stairs/JangAyeon.js diff --git a/climbing-stairs/JangAyeon.js b/climbing-stairs/JangAyeon.js new file mode 100644 index 0000000000..3cf3746d6e --- /dev/null +++ b/climbing-stairs/JangAyeon.js @@ -0,0 +1,14 @@ +/** + * @param {number} n + * @return {number} + */ +var climbStairs = function (n) { + const dp = [0, 1, 2]; + for (let i = 3; i <= n; i++) { + const value = dp[i - 2] + dp[i - 1]; + dp.push(value); + // console.log(i, value) + } + + return dp[n]; +}; From 9b5f55557fe5843b3e6f31939fdf6d3c64f0082a Mon Sep 17 00:00:00 2001 From: JangAyeon Date: Fri, 21 Nov 2025 07:39:26 +0900 Subject: [PATCH 3/5] solve 3sum --- 3sum/JangAyeon.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 3sum/JangAyeon.js diff --git a/3sum/JangAyeon.js b/3sum/JangAyeon.js new file mode 100644 index 0000000000..e7217c1278 --- /dev/null +++ b/3sum/JangAyeon.js @@ -0,0 +1,31 @@ +var threeSum = function (nums) { + let res = []; + nums.sort((a, b) => a - b); + + for (let i = 0; i < nums.length; i++) { + if (i > 0 && nums[i] === nums[i - 1]) { + continue; + } + + let j = i + 1; + let k = nums.length - 1; + + while (j < k) { + let total = nums[i] + nums[j] + nums[k]; + + if (total > 0) { + k--; + } else if (total < 0) { + j++; + } else { + res.push([nums[i], nums[j], nums[k]]); + j++; + + while (nums[j] === nums[j - 1] && j < k) { + j++; + } + } + } + } + return res; +}; From 949e83e6860153cc40d3c3f5749577d9814fe9da Mon Sep 17 00:00:00 2001 From: JangAyeon Date: Fri, 21 Nov 2025 07:40:55 +0900 Subject: [PATCH 4/5] solve product of array except self --- product-of-array-except-self/JangAyeon.js | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 product-of-array-except-self/JangAyeon.js diff --git a/product-of-array-except-self/JangAyeon.js b/product-of-array-except-self/JangAyeon.js new file mode 100644 index 0000000000..0bdbe64bec --- /dev/null +++ b/product-of-array-except-self/JangAyeon.js @@ -0,0 +1,29 @@ +/** + * @param {number[]} nums + * @return {number[]} + */ +var productExceptSelf = function (nums) { + let answer = []; + + const p = []; + for (let i = 0; i < nums.length; i++) { + if (i == 0) { + const n = nums.slice(i + 1).reduce((acc, curr) => (acc *= curr), 1); + console.log(n); + p.push([1, n]); + answer.push(1 * n); + } else { + const [left, right] = p[i - 1]; + if (nums[i] === 0) { + const n = nums.slice(i + 1).reduce((acc, curr) => (acc *= curr), 1); + p.push([left * nums[i - 1], n]); + answer.push(left * nums[i - 1] * n); + } else { + p.push([left * nums[i - 1], right / nums[i]]); + answer.push((left * nums[i - 1] * right) / nums[i]); + } + } + } + + return answer; +}; From f322c64cc5e234dabbaf24eee89ce8a4fef6d6f2 Mon Sep 17 00:00:00 2001 From: JangAyeon Date: Fri, 21 Nov 2025 07:44:42 +0900 Subject: [PATCH 5/5] solve validate binary search tree --- validate-binary-search-tree/JangAyeon.js | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 validate-binary-search-tree/JangAyeon.js diff --git a/validate-binary-search-tree/JangAyeon.js b/validate-binary-search-tree/JangAyeon.js new file mode 100644 index 0000000000..426368acd9 --- /dev/null +++ b/validate-binary-search-tree/JangAyeon.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} root + * @return {boolean} + */ +const dfs = (node, left, right) => { + if (!node) { + return true; + } + + return ( + node.val > left && + node.val < right && + dfs(node.left, left, node.val) && + dfs(node.right, node.val, right) + ); +}; + +const isValidBST = function (root) { + return dfs(root, -Infinity, Infinity); +};