From cfba5ccb6f23bda539c436619e3278fefa66f5bf Mon Sep 17 00:00:00 2001 From: doitchuu Date: Mon, 23 Feb 2026 23:13:08 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20ImplementQueueUsingStacks=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=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 --- doitchuu/ImplementQueueUsingStacks.js | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 doitchuu/ImplementQueueUsingStacks.js diff --git a/doitchuu/ImplementQueueUsingStacks.js b/doitchuu/ImplementQueueUsingStacks.js new file mode 100644 index 0000000..e17cee3 --- /dev/null +++ b/doitchuu/ImplementQueueUsingStacks.js @@ -0,0 +1,58 @@ +var MyQueue = function () { + this.inStack = []; + this.outStack = []; +}; + +/** + * @param {number} x + * @return {void} + */ +MyQueue.prototype.push = function (x) { + this.inStack.push(x); +}; + +/** + * @return {number} + */ +MyQueue.prototype.pop = function () { + if (this.outStack.length === 0) { + while (this.inStack.length) { + this.outStack.push(this.inStack.pop()); + } + } + + return this.outStack.pop(); +}; + +/** + * @return {number} + */ +MyQueue.prototype.peek = function () { + if (this.outStack.length === 0) { + while (this.inStack.length) { + this.outStack.push(this.inStack.pop()); + } + } + + const lastIndex = this.outStack.length - 1; + return this.outStack[lastIndex]; +}; + +/** + * @return {boolean} + */ +MyQueue.prototype.empty = function () { + const hasInStackValues = this.inStack.length !== 0; + const hasOutStackValues = this.outStack.length !== 0; + + return !hasInStackValues && !hasOutStackValues ? true : false; +}; + +/** + * 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() + */ From 85ecdcf750e8766955c7ef626e2ccd2a464480bd Mon Sep 17 00:00:00 2001 From: doitchuu Date: Mon, 23 Feb 2026 23:13:45 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20LinkedListCycle=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=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 --- doitchuu/LinkedListCycle.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 doitchuu/LinkedListCycle.js diff --git a/doitchuu/LinkedListCycle.js b/doitchuu/LinkedListCycle.js new file mode 100644 index 0000000..d3e6af5 --- /dev/null +++ b/doitchuu/LinkedListCycle.js @@ -0,0 +1,27 @@ +/** + * Definition for singly-linked list. + * function ListNode(val) { + * this.val = val; + * this.next = null; + * } + */ + +/** + * @param {ListNode} head + * @return {boolean} + */ +var hasCycle = function (head) { + const isVisited = new Set(); + let current = head; + + while (current) { + if (isVisited.has(current)) { + return true; + } + + isVisited.add(current); + current = current.next; + } + + return false; +}; From a7b858067ea088a244be33a0e7b5091b43a5be4c Mon Sep 17 00:00:00 2001 From: doitchuu Date: Thu, 26 Feb 2026 23:43:00 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20LowestCommonAncestorOfABinarySearch?= =?UTF-8?q?Tree=20=ED=92=80=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...LowestCommonAncestorOfABinarySearchTree.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doitchuu/LowestCommonAncestorOfABinarySearchTree.js diff --git a/doitchuu/LowestCommonAncestorOfABinarySearchTree.js b/doitchuu/LowestCommonAncestorOfABinarySearchTree.js new file mode 100644 index 0000000..67785ad --- /dev/null +++ b/doitchuu/LowestCommonAncestorOfABinarySearchTree.js @@ -0,0 +1,30 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val) { + * this.val = val; + * this.left = this.right = null; + * } + */ + +/** + * @param {TreeNode} root + * @param {TreeNode} p + * @param {TreeNode} q + * @return {TreeNode} + */ +var lowestCommonAncestor = function(root, p, q) { + const small = Math.min(p.val, q.val); + const big = Math.max(p.val, q.val); + + while (root) { + if (big < root.val) { + root = root.left; + } else if (small > root.val) { + root = root.right; + } else { + return root; + } + } + + return null; +}; From 3049bf7db4ee8826b2f48728fab6ede49b8ea934 Mon Sep 17 00:00:00 2001 From: doitchuu Date: Fri, 27 Feb 2026 10:55:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?add:=20BalancedBinaryTree=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doitchuu/BalancedBinaryTree.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 doitchuu/BalancedBinaryTree.js diff --git a/doitchuu/BalancedBinaryTree.js b/doitchuu/BalancedBinaryTree.js new file mode 100644 index 0000000..7081d0a --- /dev/null +++ b/doitchuu/BalancedBinaryTree.js @@ -0,0 +1,15 @@ +/** + * 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 isBalanced = function(root) { + +}; From d1d0c40186960cf451d41260038d0480caab85d2 Mon Sep 17 00:00:00 2001 From: doitchuu Date: Sat, 28 Feb 2026 17:14:14 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20BalancedBinaryTree=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=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 --- doitchuu/BalancedBinaryTree.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/doitchuu/BalancedBinaryTree.js b/doitchuu/BalancedBinaryTree.js index 7081d0a..542be12 100644 --- a/doitchuu/BalancedBinaryTree.js +++ b/doitchuu/BalancedBinaryTree.js @@ -11,5 +11,19 @@ * @return {boolean} */ var isBalanced = function(root) { - + function dfs(node) { + if (node === null) return 0; + + const left = dfs(node.left); + if (left === -1) return -1; + + const right = dfs(node.right); + if (right === -1) return -1; + + if (Math.abs(left - right) > 1) return -1; + + return Math.max(left, right) + 1; + } + + return dfs(root) !== -1; };