<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Node.js on Yosgi</title><link>https://yosgi.github.io/en/tags/node.js/</link><description>Recent content in Node.js on Yosgi</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 29 Jun 2026 09:20:51 +0000</lastBuildDate><atom:link href="https://yosgi.github.io/en/tags/node.js/index.xml" rel="self" type="application/rss+xml"/><item><title>865 - Minimum subtree with all deepest nodes</title><link>https://yosgi.github.io/en/post/865-minimum-subtree-with-all-deepest-nodes/</link><pubDate>Sun, 21 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/865-minimum-subtree-with-all-deepest-nodes/</guid><description>Time: 60 minutes I was misled by the depth of the question and thought that the calculation depth should be done from top to bottom. In fact, it can be done from bottom to top. If the left and right subtrees have the same height, return the node itself and its depth. If the left subtree is deeper, it means that the smallest and deepest part is in the left subtree. Return the left subtree and its own depth.</description></item><item><title>783-Binary Search Tree Node Minimum Distance</title><link>https://yosgi.github.io/en/post/783-binary-search-tree-node-minimum-distance/</link><pubDate>Thu, 18 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/783-binary-search-tree-node-minimum-distance/</guid><description>Time: 10 minutes Solve by using the property of pre-order traversal of binary tree var minDiffInBST = function(root) { var min = Infinity var pre = null var dfs = function (root) { if (!root) return if (root.left) { dfs(root.left) } if (pre == null) { pre = root.val } else { console.log(pre,root.val) var reduce = Math.abs(pre - root.val) min = Math.min(min,reduce) pre = root.val } if (root.right) { dfs(root.right) } } dfs(root) return min };</description></item><item><title>1448-Count the number of good nodes in a binary tree</title><link>https://yosgi.github.io/en/post/1448-count-the-number-of-good-nodes-in-a-binary-tree/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1448-count-the-number-of-good-nodes-in-a-binary-tree/</guid><description>Notes on counting good nodes in a binary tree using DFS with a running max.</description></item><item><title>1325-Delete the leaf node of the given value</title><link>https://yosgi.github.io/en/post/1325-delete-the-leaf-node-of-the-given-value/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1325-delete-the-leaf-node-of-the-given-value/</guid><description>Post-order traversal approach to delete target-valued leaf nodes using a dummy root.</description></item><item><title>129-Find the sum of numbers from the root node to the leaf node</title><link>https://yosgi.github.io/en/post/129-find-the-sum-of-numbers-from-the-root-node-to-the-leaf-node/</link><pubDate>Tue, 16 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/129-find-the-sum-of-numbers-from-the-root-node-to-the-leaf-node/</guid><description>The question is about starting from the root node. The first thing that comes to mind is top-down DFS, passing parameters downward, and the end condition has no left or right children. Start with the pre-order traversal, and you can assume that all the previous nodes have been processed. var sumNumbers = function(root) { var ans = 0 var DFS = function (root,path) { if (!root) return path += root.val if (!root.left &amp;&amp; !root.right) { ans += Number(path) } root.left &amp;&amp; DFS(root.left,path) DFS(root.right, path) } DFS(root,'') return ans };The question is about starting from the root node. The first thing that comes to mind is top-down DFS, passing parameters downward, and the end condition has no left or right children.</description></item><item><title>863-All nodes with distance -K- in a binary tree</title><link>https://yosgi.github.io/en/post/863-all-nodes-with-distance-k-in-a-binary-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/863-all-nodes-with-distance-k-in-a-binary-tree/</guid><description>Time: 60 minutes The idea is still very simple. First use DFS to add a parent to each node, and find the required target by the way. Then starting from the target, use DFS to find a point K away from the target. Find all the parents of target in turn and use DFS to find the point with a distance K. The reason why it takes so much time is that after finding the parent, DFS is used to find it back, causing a memory overflow.</description></item><item><title>222-Number of nodes in a complete binary tree</title><link>https://yosgi.github.io/en/post/222-number-of-nodes-in-a-complete-binary-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/222-number-of-nodes-in-a-complete-binary-tree/</guid><description>Time: 80 minutes The first reaction when I got the question was of course to solve it with DFS. But this is a complete binary tree, so we should use the properties of a complete binary tree. You can examine the depth of the left and right subtrees of the binary tree If the left depth is greater than the right depth, it means that the right side is full. The number of full nodes is 2 to the power of n - 1, plus the root is 2 to the power of n, and continue recursively on the left side.</description></item><item><title>450-Delete a node in a binary search tree</title><link>https://yosgi.github.io/en/post/450-delete-a-node-in-a-binary-search-tree/</link><pubDate>Thu, 11 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/450-delete-a-node-in-a-binary-search-tree/</guid><description>Time: 30 minutes The question is divided into two parts to be solved, search and delete The search part is to find the node. You can find the required node according to the properties of the binary search tree. There are three types of deletion If there is only a left child, replace it with the left child. If there is only a right child, replace it with the right child. If there is neither child, assign null. (Since there was a recursive assignment earlier, this will succeed.) If there are both children, store the left child, replace it with the right child, and then find the left child’s position on the right. var deleteNode = function(root, key) { function insert(root,node) { if (root.val &gt; node.val) { if (!root.left) { root.left = node } else { insert(root.left,node) } } else { if (!root.right) { root.right = node } else { insert(root.right,node) } } } function search(root) { if (!root) { return null } if (root.val &gt; key) { root.left = search(root.left) } else if (root.val &lt; key){ root.right = search(root.right) } else { if (!root.left &amp;&amp; !root.right) { root = null } else if (root.left &amp;&amp; root.right) { var left = root.left root = root.right insert(root,left) } else if (root.left) { root = root.left } else if (root.right) { root = root.right } } return root } return search(root) };Points to note</description></item><item><title>116-Fill in the next right node pointer of each node</title><link>https://yosgi.github.io/en/post/116-fill-in-the-next-right-node-pointer-of-each-node/</link><pubDate>Wed, 10 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/116-fill-in-the-next-right-node-pointer-of-each-node/</guid><description>Time: 25 minutes The main idea is to use the stack. The difference from the ordinary level-order traversal is that the stack is cleared every time var connect = function(root) { if (!root) return null var stack = [root] while(stack.length) { var _stack = [...stack,null] stack = [] var pre = _stack.shift() while(_stack.length || pre) { pre.left &amp;&amp; stack.push(pre.left) pre.right &amp;&amp; stack.push(pre.right) pre.next = _stack.shift() pre = pre.next } } return root};Obviously, the memory space of On I used does not meet the constant space requirement of the question, considering that the links of each layer can be found in the form of a linked list by relying on the parent node.</description></item><item><title>Vue + express + mongodb build a backend login system</title><link>https://yosgi.github.io/en/post/vue-express-mongodb-build-a-backend-login-system/</link><pubDate>Fri, 29 Jan 2021 17:44:40 +1300</pubDate><guid>https://yosgi.github.io/en/post/vue-express-mongodb-build-a-backend-login-system/</guid><description>Keywords nodejs vue express mongodb</description></item><item><title>Regular expression performance optimization</title><link>https://yosgi.github.io/en/post/regular-expression-performance-optimization/</link><pubDate>Tue, 06 Nov 2018 15:48:14 +1300</pubDate><guid>https://yosgi.github.io/en/post/regular-expression-performance-optimization/</guid><description>High Performance Javascript Knowledge Points</description></item></channel></rss>