2-line Java AC recursive


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

Log in to reply
 

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