Question
Given the root
of a binary tree, return its maximum depth.
A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
https://leetcode.com/problems/maximum-depth-of-binary-tree/
Solution
- Solution1 – DFS, bottom up
1 | class Solution { |
1 | bottom up general steps: |
Complexity:
Time complexity: O(n)
Space complexity: O(n)