/**
* 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 * before = NULL;
ListNode * next;
while(head != NULL){
next = head->next;
head->next = before;
before = head;
head = next;
}
return before;
}
};leetcode 206. Reverse Linked List
最新推荐文章于 2025-12-03 23:35:37 发布
419

被折叠的 条评论
为什么被折叠?



