码迷,mamicode.com
首页 > 其他好文 > 详细

LeeCode 单链表逆序

时间:2015-05-19 20:57:20      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:c语言   leecode   


题目:Reverse a singly linked list

C代码:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    if(NULL==head||NULL==head->next) return head;

    struct ListNode *p=head->next;
    head->next=NULL;
    struct ListNode *newhead=reverseList(p);
    p->next=head;

    return newhead;
    
}


LeeCode 单链表逆序

标签:c语言   leecode   

原文地址:http://blog.csdn.net/xiaoshuoladashou/article/details/45849553

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!