ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
Good Job
Mast video. Lekin mera solution thoda aur simple and easy to understand hain, thoda slow hain lekin 🤓🤓class Solution {public: TreeNode* replaceValueInTree(TreeNode* root) { queue q; root->val=0; q.push(root); while(!q.empty()) { int sum=0; queueparent; int n=q.size(); for(int i=0;ileft!=NULL) { q.push(temp->left); sum+=temp->left->val; } if(temp->right!=NULL) { q.push(temp->right); sum+=temp->right->val; } } while(!parent.empty()) { TreeNode* lul=parent.front(); parent.pop(); int nv=0; if(lul->left!=NULL) { nv+=lul->left->val; } if(lul->right!=NULL) { nv+=lul->right->val; } if(lul->left!=NULL) lul->left->val=sum-nv; if(lul->right!=NULL) lul->right->val=sum-nv; } } return root; }};
Good Job
Mast video. Lekin mera solution thoda aur simple and easy to understand hain, thoda slow hain lekin 🤓🤓
class Solution {
public:
TreeNode* replaceValueInTree(TreeNode* root)
{
queue q;
root->val=0;
q.push(root);
while(!q.empty())
{
int sum=0;
queueparent;
int n=q.size();
for(int i=0;ileft!=NULL)
{
q.push(temp->left);
sum+=temp->left->val;
}
if(temp->right!=NULL)
{
q.push(temp->right);
sum+=temp->right->val;
}
}
while(!parent.empty())
{
TreeNode* lul=parent.front();
parent.pop();
int nv=0;
if(lul->left!=NULL)
{
nv+=lul->left->val;
}
if(lul->right!=NULL)
{
nv+=lul->right->val;
}
if(lul->left!=NULL)
lul->left->val=sum-nv;
if(lul->right!=NULL)
lul->right->val=sum-nv;
}
}
return root;
}
};