题目

翻转列表

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        
        if(head==NULL|| head->next==NULL)
            return head;
        
        ListNode* term = head->next;
        head->next=NULL;
        return Fun(term,head);
        
    }
    
    ListNode* Fun(ListNode* head,ListNode* pre)
    {
        
        ListNode* term = head->next;
        
        head->next = pre;
        
        if(term!=NULL)
            return  Fun(term,head);
        else
            return head;
    }
};

相关文章:

  • 2022-02-05
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
猜你喜欢
  • 2021-06-13
  • 2021-12-06
  • 2021-08-30
  • 2021-10-13
  • 2021-12-16
  • 2021-06-24
  • 2021-12-15
相关资源
相似解决方案