Simple to understand Java Solution


  • 0
    A

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


Log in to reply
 

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