二叉树的最大深度:
PHP 20ms:
递归。
/**
* Definition for a binary tree node.
* class TreeNode {
* public $val = null;
* public $left = null;
* public $right = null;
* function __construct($value) { $this->val = $value; }
* }
*/
class Solution {
/**
* @param TreeNode $root
* @return Integer
*/
function maxDepth($root) {
return $root == null ? 0: max($this->maxDepth($root->left),$this->maxDepth($root->right))+1;
}
}