Java 2-line : Beats 83%


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

Log in to reply
 

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