/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int result;
int sumOfLeftLeaves(TreeNode* root) {
result = 0;
traversal(root);
return result;
}
void traversal(TreeNode* node) {
if (node == NULL) return;
if (node->left != NULL && node->left->left == NULL && node->left->right == NULL) {
result += node->left->val;
} else {
traversal(node->left);
}
traversal(node->right);
}
};