Java Recursive solution


  • -2
    M
    public int sumLeft(TreeNode node, boolean isLeft, int sum){
        if(node!= null){
            if(isLeft && node.left == null && node.right == null){
                sum = sum + node.val;
            }
             sum = sumLeft(node.left, true,sum);
             sum = sumLeft(node.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.