题目:
Reverse a singly linked list.
代码:看不懂,我已经没救了
1 public ListNode reverseList(ListNode head) { 2 if (head == null) return head; 3 ListNode cur = head; 4 ListNode pre = null; 5 while (cur.next != null){ 6 ListNode nextNode = cur.next; 7 cur.next = pre; 8 pre = cur; 9 cur = nextNode; 10 } 11 cur.next = pre; 12 return cur; 13 }
reference:http://blog.welkinlan.com/2015/05/06/reverse-linked-list-leetcode-java/