# Binary Tree Sum of all left leaves.

iven the `root` of a binary tree, return the sum of all left leaves.

A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

![image](https://github.com/VikashChauhan51/algorithms/assets/14816038/23d49898-7dd5-4ff9-b87d-acfc9a085bbe)

### Solution

```csharp
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left;
 *     public TreeNode right;
 *     public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
public class Solution {
   public int SumOfLeftLeaves(TreeNode root)
    {
        return DFS(root,false);
    }
    public int DFS(TreeNode root, bool isLeaf)
    {
        if (root == null)
            return 0;

        if (root.left == null && root.right == null)
        {
            return isLeaf ? root.val : 0;
        }
        return DFS(root.left, true) + DFS(root.right, false);

    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-57.gitbook.io/data-structure-and-algorithms/problems/tree/binary-tree-sum-of-all-left-leaves..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
