Simple Java 3 line code


  • 0
    Z
    
        public int sumOfLeftLeaves(TreeNode root) {
            if(root == null) return 0;
            boolean hasLeftLeave = root.left != null && root.left.left == null && root.left.right == null;
            return (hasLeftLeave ? root.left.val : 0) +  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.