1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
* Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode reverseList(ListNode head) { if(head==null){ return null; } ListNode point1 = head; ListNode point2 = head.next; ListNode point3 = (point2==null)?null:point2.next; while(point2!=null){ point3 = point2.next; point2.next = point1; point1 = point2; point2 = point3; } head.next=null; return point1; } }
|
近期评论