【LeetCode】Maximum Depth of Binary Tree

http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/

public class Solution {
    public int maxDepth(TreeNode root) {
        if(root!=null){
            int depth=0;
            InOrder(root,depth);
        }
        return max;
        
    }
    public int max=0;
    private void InOrder(TreeNode root, int depth) {
        if(root!=null){
            depth++;
            if(max<depth){
                max=depth;
            }
            InOrder(root.left,depth);
            InOrder(root.right,depth);
            depth--;
        }
        
    }
}

 

posted @ 2014-05-06 19:50  一弦一仙  阅读(90)  评论(0编辑  收藏  举报