码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 206 Reverse Linked List 链表

时间:2016-01-26 00:06:51      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

将单向链表反转

完成如图操作,依次进行即可

1

技术分享

2

技术分享

3

技术分享

 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* now = head;
13         head = NULL;
14         while(now){
15             ListNode* tnow= now;
16             now = now->next;
17             tnow->next = head;
18             head = tnow;
19         }
20         return head;
21     }
22 };

 

Leetcode 206 Reverse Linked List 链表

标签:

原文地址:http://www.cnblogs.com/onlyac/p/5158953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!