Leetcode春季打卡活动 第二题:206. 反转链表
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;
    }
};

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号