quoniammm / happy-leetcode-javascript

leetcode题解
MIT License
1 stars 0 forks source link

104 Maximum Depth of Binary Tree #3

Open quoniammm opened 8 years ago

quoniammm commented 8 years ago
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var maxDepth = function(root) {
    if(root===null){
        return 0;
    }
    return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
};