/**
* 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 == NULL )
return ;
if( root->left == NULL )
{
return ;
}
root->left->next = root->right;
root->right->next = root->next ? root->next->left : NULL;
connect( root->left );
connect( root->right );
}
};
Populating Next Right Pointers in Each Node
最新推荐文章于 2022-02-28 18:16:11 发布