Sunday, July 9, 2017

104. Maximum Depth of Binary Tree

Version #1 Recursion
15.47 %

public class Solution {
    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);
        return Math.max(leftDepth, rightDepth) + 1;
    }
}

No comments:

Post a Comment