首页 > 其他 > 详细

Leetcode 206: Reverse Linked List

时间:2018-01-31 13:52:58      阅读:205      评论:0      收藏:0      [点我收藏+]

Reverse a singly linked list.

 

 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 || head.next == null) return head;
12         
13         ListNode prev = null, cur = head;
14         
15         while (cur != null)
16         {
17             var next = cur.next;
18             cur.next = prev;
19             prev = cur;
20             cur = next;
21         }
22         
23         return prev;
24     }
25 }

 

Leetcode 206: Reverse Linked List

原文:https://www.cnblogs.com/liangmou/p/8391038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!