题解 | #链表的奇偶重排#

链表的奇偶重排

https://www.nowcoder.com/practice/02bf49ea45cd486daa031614f9bd6fc3

/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param head ListNode类 
 * @return ListNode类
 */
#include <stdbool.h>
struct ListNode* oddEvenList(struct ListNode* head ) {
    // write code here
    if(head==NULL||head->next==NULL||head->next->next==NULL){
        return head;
    }
    struct ListNode *head1=head,*head2=head->next;
    struct ListNode *p=head1,*q=head2,*t=head->next->next;
    bool flag=true;
    while (t!=NULL) {
        if(flag){
            p->next=t;
            p=p->next;
        }else{
            q->next=t;
            q=q->next;
        }
        t=t->next;
        flag=!flag;
        p->next=NULL;
        q->next=NULL;
    }
    p->next=head2;
    return head1;
}

全部评论

相关推荐

沉淀去了,8月是不是机会会多一点,。打招呼300+,就一个小厂面试,聊了十分钟天就让我去了,暑假继续沉淀了,到八月九月冲了
丰川打工祥:我目前的体感是,双非本+一段小厂实习,基本约不到中厂的面。已经开始第二段小厂了。可能的确是最近hc太少了。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-20 14:14
点赞 评论 收藏
分享
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务