Maximum Depth of Binary Tree
https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
Easy 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.
Thoughts
简单但很好体现了分治基本思想的一道题。先左后右再合并。树的最高深度是子树中最高深度 + 1。
Code
Analysis
因为相当于把数遍历了遍,所以时间复杂度为O(n), n为结点数。
Ver. 2
Iterative + meta stack解法.
PreviousConvert Sorted Array to Binary Search TreeNext1430. Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree
Last updated
Was this helpful?