C++ 反转链表代码实现
/**
- 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; } };
原文地址: https://www.cveoy.top/t/topic/nKiV 著作权归作者所有。请勿转载和采集!