/**

  • 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) { ListNode* prev = NULL; while (head) { ListNode* next = head->next; head->next = prev; prev = head; head = next; } return prev; } };
C++ 反转链表代码实现

原文地址: https://www.cveoy.top/t/topic/nKiV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录