102. Binary Tree Level Order Traversal (BFS)

BFS Traversal

問題點

在每一層遍歷開始前,先記錄隊列中的結點數量 n

所以需要利用當前 queue 的 size 當分層的數量

但如果不是樹的題目

因為不是樹, 所以不用 queue size 來分層遍歷

Last updated

Was this helpful?