左叶子指的是,节点的左孩子不为空,但左孩子的左右孩子为空,哪么左孩子为左叶子节点
class Solution {
public:
int sumOfLeftLeaves(TreeNode* root) {
if(root==NULL)return 0;
if(root->left==NULL && root->right==NULL)return 0;
int leftvalue=sumOfLeftLeaves(root->left);
if(root->left!=nullptr && root->left->left==NULL &&root->left->right==NULL)
{leftvalue=root->left->val;}
int right=sumOfLeftLeaves(root->right);
int sum=leftvalue+right;
return sum;
}
};