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
原题链接
使用队列进行广度优先遍历,level 数组存放当前层级的值,处理完一层后推入结果数组 result。
const levelOrder = function(root) { if (root == null) return [] const result = [] const queue = [root] while (queue.length > 0) { const levelSize = queue.length const level = [] for (let i = 0; i < levelSize; i++) { const head = queue.shift() for (const child of head.children) { queue.push(child) } level.push(head.val) } result.push(level) } return result }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
队列 bfs
使用队列进行广度优先遍历,level 数组存放当前层级的值,处理完一层后推入结果数组 result。
The text was updated successfully, but these errors were encountered: