5/30/2014

02. Maximum Depth of Binary Tree

/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public int maxDepth(TreeNode root) {
        if (root==null) return 0;
       
        int res = 0;
       
        return res = Math.max(maxDepth(root.left)+1, maxDepth(root.right)+1);
    }
}

1 条评论: