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

反转链表

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;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-01 13:13
ecece:这么明目张胆虚报就业率啊
点赞 评论 收藏
分享
每晚夜里独自颤抖:1600一个月?
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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