637. Average of Levels in Binary Tree
題目網址:https://leetcode.cn/problems/average-of-levels-in-binary-tree/
題意:給一 Binary Tree(BT), 計算每一層的平均值。
Solution:
想法:利用 BFS
class Solution { |
- time:$O(n)$ ➔ 遍歷整個 BT
- space:$O(n)$ ➔ 取決於樹的高度, worse case 為 skew tree, tree
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Zako's Blog!
評論