/**
* 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;
if(root->left==NULL)return;
root->left->next=root->right;
if(root->next)
root->right->next=root->next->left;
connect(root->left);
connect(root->right);
}
};
leetcode116. Populating Next Right Pointers in Each Node
最新推荐文章于 2023-11-09 13:02:00 发布