Java Divide Conquer Solution


  • 0
    M

    class Solution {
    public int sumOfLeftLeaves(TreeNode root) {
    if(root == null) return 0;
    return helper(root.left, true) + helper(root.right, false);
    }
    private int helper(TreeNode root, boolean isLeft) {
    if(root == null) return 0;
    if(root.left == null && root.right == null) return isLeft? root.val : 0;
    return helper(root.left, true) + helper(root.right, false);
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.