We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
树具有子结构,一旦涉及子问题,考虑使用「递归」完成。
�如果出现顺序的数组,要组成一个二叉搜索树,那么用中序遍历。因为 BST 的中序遍历是升序的。
关键使用「队列」,从左到右,从上到下的便利
const BFS = function(root) { if (!root) { return [] } let queue = [root] const res = [] while (queue.length > 0) { const node = queue.shift() res.push(node.val) if (node.left) { queue.push(node.left) } if (node.right) { queue.push(node.right) } } console.log(res) return res }
步骤:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
树具有子结构,一旦涉及子问题,考虑使用「递归」完成。
中序遍历
�如果出现顺序的数组,要组成一个二叉搜索树,那么用中序遍历。因为 BST 的中序遍历是升序的。
层次遍历
关键使用「队列」,从左到右,从上到下的便利
步骤:
The text was updated successfully, but these errors were encountered: