MCPcopy Create free account
hub / github.com/algorithm004-03/algorithm004-03 / levelOrder

Function levelOrder

Week 03/id_198/LeetCode_102_198.go:21–50  ·  view source on GitHub ↗

本部分基于BFS(一种遍历或搜索树或图数据结构的算法。它从树根(或图的某个任意节点)开始,在进入下一个深度级别之前,探测当前深度的所有邻居节点 可能和老师的模板有一定出入, 本实现在完成当前节点遍历当前深度(所有)节点时将下一级节点缓存,以便下次访问。 每个节点在该过程中至少访问两次,因此时间复杂度为O(2b^d)=>O(b^d) 中间存在暂存行为,因此空间复杂度为O(b^d)

(root *TreeNode)

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers 1

Test_levelOrderFunction · 0.70

Calls

no outgoing calls

Tested by 1

Test_levelOrderFunction · 0.56