Given 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.

&nbsp;
Example 1:

Input: root = [3,9,20,null,null,15,7]
Output: 24
Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.


Example 2:

Input: root = [1]
Output: 0


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [1, 1000].
	-1000 &lt;= Node.val &lt;= 1000


def is_leaf(x):
    return x.left is None and x.right is None

class Solution:
    def sumOfLeftLeaves(self, root: Optional[TreeNode]) -> int:
        if root is None:
            return 0
        if root.left and is_leaf(root.left):
            left = root.left.val
        else:
            left = self.sumOfLeftLeaves(root.left)
        return left + self.sumOfLeftLeaves(root.right)
class Solution {
    public int sumOfLeftLeaves(TreeNode root) {

        if(root==null)
            return 0;

        if(root.left!=null && root.left.left==null && root.left.right==null){
            return root.left.val + sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
        }else{
            return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
        }

    }
}
class Solution {
    int sum=0;
public:
    bool solve(TreeNode* root){
        if(root==NULL) return false;
        if(root->left==NULL && root->right==NULL) return true;
        if(solve(root->left)) sum+=root->left->val;
        solve(root->right);
        return false;
    }
    int sumOfLeftLeaves(TreeNode* root) {
        solve(root);
        return sum;
    }
};
var sumOfLeftLeaves = function(root) {
    let total = 0;
    
    const go = (node, isLeft) => {
        if (isLeft && !node.left && !node.right) {
            total += node.val;
            return;
        }
        if (node.left) go(node.left, true);
        if (node.right) go(node.right, false)
    }
    
    go(root, false)
    
    return total;
};
Sum of Left Leaves