maine queue mei jb root push kr rhe the jbhi reverse krke daala by phele right ko fir left ko ,pr iss sol se sre given test case satisfy ho rhe pr bhut sre edge cases miss ho rhe plz highlight the mistake vector zigzagLevelOrder(TreeNode* root) { int count=1; //bfs traversal vectorans; //edge case if(!root) return {}; queueq; q.push(root); while(!q.empty()){ count++; vectortemp; int size=q.size(); for(int i=0;iright)q.push(node->right); if(node->left)q.push(node->left); } else{ if(node->left)q.push(node->left); if(node->right)q.push(node->right); } temp.push_back(node->val); count++; } ans.push_back(temp); } return ans;
Thank you so much sir !
Your explanation for level order and zig zag traversal question make me understand the logic clearly.
You are most welcome
I did it on my own after watching your level order video, this felt like a piece of cake
Thanks a lot Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
aapke wajah se yeh meh khud kar paya hoon,graph karne ke baad yeh playlist bijli ki speed se ho raha hai
Bahot badiya explanation bhiya. 🙏🙏
Again thanks dear
Sir apka solution optimize solution nahi he issme riverse vala extra time lagta he.
best explanation and code keep it up
Thanks 😌
Keep sharing my channel with your friends and colleagues
dhanyavad bhai
Keep learning dost
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
vaiiia aap regular vedo dala ki jiye
Sure 😃
Thank you Bhaiya
Thanks
Welcome
thanks bro
🙃
Welcome 😊
Why cant we use flag and do the operation of inserting into queue in opposite direction
thanks Buddy 😁😁😁😁😁😁
No problem 👍
ai se hi bhaia pen paper se samjhaie
best hein rathen than slide
Thanks a lot for supporting me
maine queue mei jb root push kr rhe the jbhi reverse krke daala by phele right ko fir left ko ,pr iss sol se sre given test case satisfy ho rhe pr bhut sre edge cases miss ho rhe plz highlight the mistake
vector zigzagLevelOrder(TreeNode* root) {
int count=1;
//bfs traversal
vectorans;
//edge case
if(!root) return {};
queueq;
q.push(root);
while(!q.empty()){
count++;
vectortemp;
int size=q.size();
for(int i=0;iright)q.push(node->right);
if(node->left)q.push(node->left);
}
else{
if(node->left)q.push(node->left);
if(node->right)q.push(node->right);
}
temp.push_back(node->val);
count++;
}
ans.push_back(temp);
}
return ans;
Waoooò
better and less calc needed
bool flag
each time !flag
hey in the question they are asking to return a vector not a vector of vector so how to deal with it?
use
for(auto i : data)
{
ans.push_back(i);
}
and then
return the ans.
vector to std::vector return ans; how solve this problem
kya problem aa rha bro ismee
sir issme kya problem aaya hai
vector zigzagLevelOrder(TreeNode* root) {
vector ans;
queue q;
q.push(root);
int level=0;
if(root==NULL)
return ans;
while(1)
{
int size=q.size();
if(size==0)
return ans;
level++;
vectordata;
while(size>0){
TreeNode *temp=q.front();
q.pop();
data.push_back(temp->val);
if(level%2==0)
{
if(temp->right!=NULL)
q.push(temp->right);
if(temp->left!=NULL)
q.push(temp->left);
}
else
{
if(temp->left!=NULL)
q.push(temp->left);
if(temp->right!=NULL)
q.push(temp->right);
}
size--;
}
ans.push_back(data);
}
return ans;
}
@Hello World
Error arha kya ?