设为首页 加入收藏

TOP

LeeCode 单链表逆序
2015-11-21 01:01:43 来源: 作者: 【 】 浏览:1
Tags: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;
    
}


?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c++11 中的移动构造函数 下一篇HDU - 4565 So Easy! 矩阵快速幂

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: