class Solution {
private:
int count=0;
void sumhelper(TreeNode* root,bool isleft)
{
if(!root)
return;
if(isleft&&!root->left&&!root->right)
count+=root->val;
if(root->left)
sumhelper(root->left,true);
if(root->right)
sumhelper(root->right,false);
}
public:
int sumOfLeftLeaves(TreeNode* root) {
sumhelper(root,false);
return count;
}
};
404. Sum of Left Leaves
最新推荐文章于 2019-11-12 14:09:11 发布