Problem
Given a binary tree, find the leftmost value in the last row of the tree.
Examples
1 | Input: |
1 | Input: |
What If?
- Input is an empty tree?
Solution1
Method: Breadth-first Search
Time Complexity: O(n)
Space Complexity:
1 | class Solution: |
or
1 | class Solution: |
Solution2
Method: Depth-first Search
Time Complexity: O(n)
Space Complexity:
1 | class Solution: |