From 82e47ee05b3b5abac7b811633045f1414d129e0f Mon Sep 17 00:00:00 2001 From: seulgichu Date: Fri, 13 Mar 2026 07:19:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Add=20Binary=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doitchuu/AddBinary.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 doitchuu/AddBinary.js diff --git a/doitchuu/AddBinary.js b/doitchuu/AddBinary.js new file mode 100644 index 0000000..8889300 --- /dev/null +++ b/doitchuu/AddBinary.js @@ -0,0 +1,23 @@ +/** + * @param {string} a + * @param {string} b + * @return {string} + */ +var addBinary = function(a, b) { + let i = a.length - 1; + let j = b.length - 1; + let carry = 0; + let result = ""; + + while (i >= 0 || j >= 0 || carry) { + let sum = carry; + + if (i >= 0) sum += Number(a[i--]); + if (j >= 0) sum += Number(b[j--]); + + result = String(sum % 2) + result; + carry = Math.floor(sum / 2); + } + + return result; +}; From 3fbd46906bde98987eff53d5e0c4c470e81c03cf Mon Sep 17 00:00:00 2001 From: seulgichu Date: Fri, 13 Mar 2026 07:20:41 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20Diameter=20of=20Binary=20Tree=20?= =?UTF-8?q?=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/DiameterOfBinaryTree.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 doitchuu/DiameterOfBinaryTree.js diff --git a/doitchuu/DiameterOfBinaryTree.js b/doitchuu/DiameterOfBinaryTree.js new file mode 100644 index 0000000..1ae5cc9 --- /dev/null +++ b/doitchuu/DiameterOfBinaryTree.js @@ -0,0 +1,29 @@ +/** + * 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 diameterOfBinaryTree = function(root) { + let diameter = 0; + + function dfs(node) { + if (node === null) return 0; + + const left = dfs(node.left); + const right = dfs(node.right); + + diameter = Math.max(diameter, left + right); + + return Math.max(left, right) + 1; + } + + dfs(root); + return diameter; +};