0
点赞
收藏
分享

微信扫一扫

力扣------ 填充每个节点的下一个右侧节点指针

罗子僧 2022-03-12 阅读 65

在这里插入图片描述

/**
 * Definition for a Node.
 * struct Node {
 *     int val;
 *     struct Node *left;
 *     struct Node *right;
 *     struct Node *next;
 * };
 */

struct Node* connect(struct Node* root) {
    if(root==NULL){
        return NULL;
    }
    if(root->left==NULL&&root->right==NULL){
        return root;
    }
    root->left->next=root->right;
    if(root->next!=NULL){
        root->right->next=root->next->left;
    }
    connect(root->left);
    connect(root->right);
    return root;
}
举报

相关推荐

0 条评论