From b6c88ecc35bf9b830f3f1d5365fd834d12665046 Mon Sep 17 00:00:00 2001 From: sik9252 Date: Mon, 23 Feb 2026 21:34:45 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20LowestCommonAncestorOfBinarySearchT?= =?UTF-8?q?ree=20=ED=92=80=EC=9D=B4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LowestCommonAncestorOfBinarySearchTree.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sik9252/LowestCommonAncestorOfBinarySearchTree.js diff --git a/sik9252/LowestCommonAncestorOfBinarySearchTree.js b/sik9252/LowestCommonAncestorOfBinarySearchTree.js new file mode 100644 index 0000000..73fba13 --- /dev/null +++ b/sik9252/LowestCommonAncestorOfBinarySearchTree.js @@ -0,0 +1,17 @@ +var lowestCommonAncestor = function (root, p, q) { + let cur = root; + const low = Math.min(p.val, q.val); + const high = Math.max(p.val, q.val); + + while (cur !== null) { + if (high < cur.val) { + cur = cur.left; + } else if (low > cur.val) { + cur = cur.right; + } else { + return cur; + } + } + + return null; +}; From 1a55c99fcb5647ab033110ecd83f4475b75ae5fb Mon Sep 17 00:00:00 2001 From: sik9252 Date: Mon, 23 Feb 2026 21:34:58 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20BalancedBinaryTree=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sik9252/BalancedBinaryTree.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sik9252/BalancedBinaryTree.js diff --git a/sik9252/BalancedBinaryTree.js b/sik9252/BalancedBinaryTree.js new file mode 100644 index 0000000..f5c48c6 --- /dev/null +++ b/sik9252/BalancedBinaryTree.js @@ -0,0 +1,19 @@ +var isBalanced = function (root) { + function getHeight(node) { + if (node === null) return 0; + return Math.max(getHeight(node.left), getHeight(node.right)) + 1; + } + + function check(node) { + if (node === null) return true; + + const leftH = getHeight(node.left); + const rightH = getHeight(node.right); + + if (Math.abs(leftH - rightH) > 1) return false; + + return check(node.left) && check(node.right); + } + + return check(root); +}; From cf193aa2aec30d9bc55b0bd75f7813498fb8a266 Mon Sep 17 00:00:00 2001 From: sik9252 Date: Tue, 24 Feb 2026 10:05:41 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20Linked=20List=20Cycle=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sik9252/LinkedListCycle.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sik9252/LinkedListCycle.js diff --git a/sik9252/LinkedListCycle.js b/sik9252/LinkedListCycle.js new file mode 100644 index 0000000..1055f92 --- /dev/null +++ b/sik9252/LinkedListCycle.js @@ -0,0 +1,15 @@ +var hasCycle = function (head) { + const visited = new Set(); + let cur = head; + + while (cur !== null) { + if (visited.has(cur)) { + return true; + } + + visited.add(cur); + cur = cur.next; + } + + return false; +}; From 5969b512b971d532e27e2e95326101352b071c2b Mon Sep 17 00:00:00 2001 From: sik9252 Date: Tue, 24 Feb 2026 10:05:55 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20Implement=20Queue=20using=20Stacks?= =?UTF-8?q?=20=ED=92=80=EC=9D=B4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sik9252/ImplementQueueUsingStacks.js | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sik9252/ImplementQueueUsingStacks.js diff --git a/sik9252/ImplementQueueUsingStacks.js b/sik9252/ImplementQueueUsingStacks.js new file mode 100644 index 0000000..9e40280 --- /dev/null +++ b/sik9252/ImplementQueueUsingStacks.js @@ -0,0 +1,57 @@ +var MyQueue = function () { + this.stack = []; +}; + +/** + * @param {number} x + * @return {void} + */ +MyQueue.prototype.push = function (x) { + this.stack.push(x); +}; + +/** + * @return {number} + */ +MyQueue.prototype.pop = function () { + if (this.stack.length === 1) { + return this.stack.pop(); + } + + const top = this.stack.pop(); + const result = this.pop(); + this.stack.push(top); + + return result; +}; + +/** + * @return {number} + */ +MyQueue.prototype.peek = function () { + if (this.stack.length === 1) { + return this.stack[this.stack.length - 1]; + } + + const top = this.stack.pop(); + const result = this.peek(); + this.stack.push(top); + + return result; +}; + +/** + * @return {boolean} + */ +MyQueue.prototype.empty = function () { + return this.stack.length === 0; +}; + +/** + * Your MyQueue object will be instantiated and called as such: + * var obj = new MyQueue() + * obj.push(x) + * var param_2 = obj.pop() + * var param_3 = obj.peek() + * var param_4 = obj.empty() + */