Reverse Linked List
问题:
Reverse a singly linked list.
思路:
插入排序的应用
我的代码:
public class Solution { public ListNode reverseList(ListNode head) { if(head==null || head.next==null) return head; ListNode dummy = new ListNode(-1); dummy.next = head; ListNode cur = head.next; while(cur != null) { ListNode next = cur.next; cur.next = dummy.next; dummy.next = cur; cur = next; } head.next = null; return dummy.next; } }