class Solution {
private:
int mindep = 100000;
int tatol = 0;
public:
void getout(TreeNode* root ,int dep)
{
if(root == nullptr)
{
return;
}
if(root->left == nullptr && root->right == nullptr)
{
if(dep < mindep)
{
mindep = dep;
tatol = root->val;
}
else if(dep == mindep)
{
tatol += root->val;
}
}
getout(root->left,dep+1);
getout(root->right,dep+1);
}
int deepestLeavesSum(TreeNode* root) {
getout(root,0);
return tatol;
}
};
求最浅叶节点之和
最新推荐文章于 2024-10-05 10:23:36 发布