class Solution {
public:
Node* connect(Node* root) {
if(!root) return nullptr;
Node *p = root->next;
if(p) {
p = p->left; //让p指向root结点右子树的右兄弟结点
}
if(root->right) root->right->next = p;
if(root->left) root->left->next = root->right;
connect(root->right);
connect(root->left);
return root;
}
};