404. Sum of Left Leaves
作者:
安东可 | 来源:发表于
2018-04-16 22:46 被阅读16次
404. Sum of Left Leaves
[思路]
int sumOfLeftLeaves(TreeNode* root) {
if(! root)return 0;
int sum =0;
sum += sumofleft(root->left,true);
sum +=sumofleft(root->right,false);
return sum;
}
int sumofleft(TreeNode* root, bool left){
if(!root) return 0;
if(! root->left && !root->right && left)
return root->val;
return sumofleft(root->left,true) + sumofleft(root->right,false);
}
本文标题:404. Sum of Left Leaves
本文链接:https://www.haomeiwen.com/subject/xzsykftx.html
网友评论