Simple Recursive 6 lines Java solution

  • 0

    public class Solution {
    public int sumOfLeftLeaves(TreeNode root) {

        return sumOfLeftLeaves(root,false);
    private int sumOfLeftLeaves(TreeNode cur, boolean isLeft){
            return 0;
        if(isLeft && (cur.left==null && cur.right==null)){
            return cur.val;
            return  sumOfLeftLeaves(cur.left,true)+ sumOfLeftLeaves(cur.right,false);


Log in to reply

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