mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
cpp
This commit is contained in:
parent
27f8d76eaf
commit
3e69bb55b4
@ -263,7 +263,30 @@ vector<int> MySort(vector<int>& arr) {
|
|||||||
[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list/)
|
[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list/)
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
// ListNode* reverseList(ListNode* head) {
|
||||||
|
// if(!head)return NULL;
|
||||||
|
// auto a = head,b = head->next;
|
||||||
|
// while(b)
|
||||||
|
// {
|
||||||
|
// auto c = b->next;
|
||||||
|
// b->next= a;
|
||||||
|
// a = b;
|
||||||
|
// b = c;
|
||||||
|
// }
|
||||||
|
// head->next = NULL;
|
||||||
|
// return a;
|
||||||
|
// }
|
||||||
|
ListNode * reverseList(ListNode * head)
|
||||||
|
{
|
||||||
|
if(!head || !head->next)return head;
|
||||||
|
auto tail = reverseList(head->next);
|
||||||
|
head->next->next = head;
|
||||||
|
head->next = NULL;
|
||||||
|
return tail;
|
||||||
|
}
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user