Another simple solution


  • 0
    D
    public int sumOfLeftLeaves(TreeNode root) {
        boolean isLeft = false;
        int sum = 0;
        return sumLeft(root,isLeft,sum);
        
    }
    
    public int sumLeft(TreeNode root,boolean isLeft,int sum)
    {
         if(root == null)
            return sum;
        if(root.left == null && root.right == null && isLeft){
            sum+=root.val;        
        }
        sum = sumLeft(root.left,true,sum); 
        sum = sumLeft(root.right,false,sum);
        return sum;
    }

Log in to reply
 

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