首页 > 其他 > 详细

Leetcode春季打卡活动 第二题:206. 反转链表

时间:2020-03-02 12:45:42      阅读:60      评论:0      收藏:0      [点我收藏+]

Leetcode春季打卡活动 第二题:206. 反转链表

206. 反转链表

Talk is cheap . Show me the code .

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* h;
    void DFS(ListNode* head){
        if(head==NULL) return ;
        if(head->next==NULL){
            h=head;
            return;
        }
        DFS(head->next);
        head->next->next=head;
        head->next=NULL;
    }
    ListNode* reverseList(ListNode* head) {
        DFS(head);
        return h;
    }
};

Leetcode春季打卡活动 第二题:206. 反转链表

原文:https://www.cnblogs.com/cell-coder/p/12394520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!