Simple Java 5 line solution with helper

  • 0
    public class Solution {
        public int sumOfLeftLeaves(TreeNode root) {
            return sumOfLeft(root,false);
        public int sumOfLeft(TreeNode root, boolean isLeft){
                return 0;
            else if (isLeft && root.left==null && root.right==null)
                return root.val;
            return sumOfLeft(root.left,true)+sumOfLeft(root.right,false);

Log in to reply

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