文章目录
- 前言
- 1.题目
- 2.代码思路
- 3.参考代码
前言
Leetcode—反转链表
1.题目
2.代码思路
3.参考代码
/*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode* reverseList(struct ListNode* head) {ListNode*prev=NULL;ListNode*cur=head;while(cur){ListNode*next=cur->next;//未来出于现在cur->next=prev;//现在指向过去prev=cur;//过去成为现在cur=next;//现在成为未来}return prev;//生之将亡,唯过去返回彼岸}