206. Reverse Linked List
生活随笔
收集整理的這篇文章主要介紹了
206. Reverse Linked List
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Reverse a singly linked list.
?
反轉(zhuǎn)單鏈表
?
C++(9ms):? 迭代
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution { 10 public: 11 ListNode* reverseList(ListNode* head) { 12 ListNode* pre = NULL ; 13 while(head){ 14 ListNode* temp = head->next ; 15 head->next = pre ; 16 pre = head ; 17 head = temp ; 18 } 19 return pre ; 20 } 21 };
?
轉(zhuǎn)載于:https://www.cnblogs.com/mengchunchen/p/8117009.html
總結(jié)
以上是生活随笔為你收集整理的206. Reverse Linked List的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求亲字开头的成语接龙!
- 下一篇: 小程序中点击input控件键盘弹出时pl