原题题目
代码实现(首刷自解)
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/int maxlevel;
int sum;void depthfirstsearch(struct TreeNode* root,int level)
{
if(root){
if(level + 1 > maxlevel){
sum = root->val;maxlevel = level + 1;}else if(level + 1 == maxlevel)sum += root->val;depthfirstsearch(root->left,level+1);depthfirstsearch(root->right,level+1);}
}int deepestLeavesSum(struct TreeNode* root){
maxlevel = 0,sum = 0;depthfirstsearch(root,0);return sum;
}