> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/tree/404.-sum-of-left-leaves.md).

# 404. Sum of Left Leaves

```java
class Solution {
    public int sumOfLeftLeaves(TreeNode root) {
        // value of current node to return:
        // it's left leaf val
        if(root==null) return 0;
        int sum = 0;
        if(root.left!=null && root.left.left == null && root.left.right == null){
            sum+=root.left.val;
        }
        sum+=sumOfLeftLeaves(root.left);
        sum+=sumOfLeftLeaves(root.right);
        return sum;
    }
}
```

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

        return recursion(root, false);
    }
    
    private int recursion(TreeNode node, boolean isLeft){
        if(node==null) return 0;
        int sum = 0;
        if(node.left==null && node.right==null && isLeft) sum+=node.val;
        sum+=recursion(node.left, true);
        sum+=recursion(node.right, false);
        return sum;
    }
}
```
