首页 > 其他 > 详细

LeetCode: Reverse Linked List

时间:2015-06-03 15:12:28      阅读:210      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!