0
点赞
收藏
分享

微信扫一扫

206. Reverse Linked List

秀妮_5519 2022-07-12 阅读 67
编程语言

problem

​​206. Reverse Linked List​​

code

Iteration

206. Reverse Linked List_其它

206. Reverse Linked List_其它_02

/**
* 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* pre = NULL;
ListNode* cur = head;
while(cur)
{
ListNode* tmp = cur->next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre;
}
};

View Code

 

 

参考

1. ​​Leetcode_Reverse Linked List​​;

举报

相关推荐

0 条评论