题解 | #反转链表#笨蛋方法

反转链表

http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca

struct ListNode* ReverseList(struct ListNode* pHead ) {
    // write code here
    if(!pHead)
        return pHead;
    struct ListNode *p,*x;
    struct ListNode *head;
    head=(struct ListNode*)malloc(sizeof(struct ListNode));
    head->next=NULL;
    p=pHead;
    while(p)
    {
        x = (struct ListNode*)malloc(sizeof(struct ListNode));
        x->val=p->val;
        x->next=head->next;
        head->next=x;
        p=p->next;
    }
    return head->next;
}

全部评论

相关推荐

在看牛客的社畜很积极:身高体重那一行信息去掉,学校那一行的信息放上面,找半天都没找到你是哪个学校什么专业的
点赞 评论 收藏
分享
迷茫的大四🐶:那你问他上班之后老实了没
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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