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

LeetCode: Reverse Linked List

时间:2015-06-03 15:13:13      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:

C#

技术分享
 1 /**
 2  * Definition for singly-linked list.
 3  * public class ListNode {
 4  *     public int val;
 5  *     public ListNode next;
 6  *     public ListNode(int x) { val = x; }
 7  * }
 8  */
 9 public class Solution {
10     public ListNode ReverseList(ListNode head) {
11         if (head == null) return null;
12         ListNode p = head, pPre = null;
13         while (p != null) {
14             ListNode pNext = p.next;
15             p.next = pPre;
16             pPre = p;
17             p = pNext;
18         }
19         return pPre;
20     }
21 }
View Code

 

LeetCode: Reverse Linked List

标签:

原文地址:http://www.cnblogs.com/yingzhongwen/p/4548913.html

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