Simple Java solution: easy to understand


  • 0
    P
    public int sumOfLeftLeaves(TreeNode root, boolean leftChild) {
            if(root == null){
                return 0;
            }
            if(root.left==null && root.right == null && leftChild){
                return root.val;
            }
            return sumOfLeftLeaves(root.left, true) + sumOfLeftLeaves(root.right, false);
        }
    }
    

Log in to reply
 

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