/** * 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 sumOfLeftLeaves(TreeNode* root, bool isLeft = false) { int res = 0; if (root == NULL) return res; if (root->left == NULL && root->right == NULL && isLeft) return root->val; res += sumOfLeftLeaves(root->left, true); res += sumOfLeftLeaves(root->right, false); return res; } };