4 Line Java Solution


  • 0
    Y
    class Solution {
        public int sumOfLeftLeaves(TreeNode root) {
            if(root == null) return 0;
            if(root.left == null) return sumOfLeftLeaves(root.right);
            else if(root.left.right == null && root.left.left == null) return root.left.val + sumOfLeftLeaves(root.right);
            else return sumOfLeftLeaves(root.right) + sumOfLeftLeaves(root.left);
            
        }
    }
    

Log in to reply
 

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