104 Maximum Depth of Binary Tree
104. Maximum Depth of Binary Tree
1. Question
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
2. Implementation
(1) DFS
(2) BFS
3. Time & Space Complexity
DFS: 时间复杂度:O(n), 空间复杂度O(h)
BFS: 时间复杂度:O(n), 空间复杂度O(w), w为一层中有最多node的个数
Last updated