网址:https://leetcode.com/problems/reverse-linked-list/

直接参考92:https://www.cnblogs.com/tornado549/p/10639756.html

/**
 * 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)
            return NULL;
        ListNode* a = NULL;
        ListNode* b = head;
        ListNode* c = b->next;
        while(c)
        {
            b->next = a;
            a = b;
            b = c;
            c = c->next;
        }
        b->next = a;
        return b;
    }
};

91. Reverse Linked List 反转链表

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2021-12-17
  • 2022-01-12
  • 2022-03-01
  • 2022-12-23
相关资源
相似解决方案