Find the sum of all left leaves in a given binary tree.
    Example: 3 / \ 9 20 / \ 15 7

    There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
    Runtime: 4 ms, faster than 75.60% of C++ online submissions for Sum of Left Leaves.

    1. /**
    2. * Definition for a binary tree node.
    3. * struct TreeNode {
    4. * int val;
    5. * TreeNode *left;
    6. * TreeNode *right;
    7. * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    8. * };
    9. */
    10. class Solution {
    11. public:
    12. int sumOfLeftLeaves(TreeNode* root) {
    13. if (root == NULL) {
    14. return 0;
    15. }
    16. int sum = 0;
    17. if (root->left != NULL) {
    18. if (root->left->left == NULL && root->left->right == NULL) { // isLeaf
    19. sum += root->left->val;
    20. } else {
    21. sum += sumOfLeftLeaves(root->left);
    22. }
    23. }
    24. if (root->right != NULL) {
    25. sum += sumOfLeftLeaves(root->right);
    26. }
    27. return sum;
    28. }
    29. };