Recursive 1 line Java, beats 73.68%, hard to read


  • 0
    I

    It's hard to read. We have a lot of easy to read solutions from other posts already. Just for fun :)
    sum of left leaves = my left leaf val + right's left leaves sum + left's left leaves sum

    public int sumOfLeftLeaves(TreeNode root) {
        return ((root == null || root.left == null) ? 0 : sumOfLeftLeaves(root.left)) + ((root == null || root.right == null) ? 0 : sumOfLeftLeaves(root.right)) + ((root != null && root.left != null && root.left.left == null && root.left.right == null) ? root.left.val : 0);
    }
    

Log in to reply
 

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