keep learning, keep coding!
Problem - Maximum Depth of Binary Tree
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.
翻譯蒟蒻
計算二元樹的最大深度。
Example 1:
1
2Input: root = [3,9,20,null,null,15,7]
Output: 3Example 2:
1
2Input: root = [1,null,2]
Output: 2
使用遞迴方式來找出二元樹的最大深度。
Solution - JavaScript
1 | /** |
Solution - Ruby
1 | def max_depth(root) |
Solution - PHP
1 | function maxDepth($root) { |