/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
void connect(TreeLinkNode *root)
{
if(!root)
return;
TreeLinkNode* LeftWall=root;
while(LeftWall)
{
TreeLinkNode* cur=LeftWall;
while(cur)
{
if(cur->left)
cur->left->next=cur->right;
if(cur->right&& cur->next)
cur->right->next=cur->next->left;
cur=cur->next;
}
LeftWall=LeftWall->left;
}
}
};
Populating Next Right Pointers in Each Node
最新推荐文章于 2021-09-24 12:05:40 发布