[leetcode]Maximum Depth of Binary Tree
简单题。顺手就写出来了。
public class Solution {
    public int maxDepth(TreeNode root) {
        // Start typing your Java solution below
        // DO NOT write main() function        
        if (root == null) return 0;
        if (root.left == null && root.right == null) return 1;
        int lmax = maxDepth(root.left) + 1;
        int rmax = maxDepth(root.right) + 1;
        return Math.max(lmax, rmax);       
    }
}
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号