404. Sum of Left Leaves

来源:互联网 发布:sql计算留存率算法 编辑:程序博客网 时间:2024/05/01 00:30
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;    }};
1 0
原创粉丝点击