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

leetcode 206

时间:2016-11-14 17:53:57      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:ever   turn   ems   style   class   https   sel   mil   microsoft   

206. Reverse Linked List

Reverse a singly linked list.

翻转一个单链表。

代码如下:

 

 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         ListNode* cur = head;
14         while(cur != NULL)
15         {
16             ListNode* temp = cur->next;
17             cur->next = pre;
18             pre = cur;
19             cur = temp;
20         }
21         return pre;
22     }
23 };

 

 

 

leetcode 206

标签:ever   turn   ems   style   class   https   sel   mil   microsoft   

原文地址:http://www.cnblogs.com/shellfishsplace/p/6062239.html

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