反转链表

public ListNode ReverseList(ListNode head) {
        if (head == null)
            return null;
        ListNode dummy = new ListNode(-1);
        ListNode second = null;
        while (head != null) {
            second = head.next;
            head.next = dummy.next;
            dummy.next = head;
            head = second;
        }
        return dummy.next;
}
posted @ 2018-10-11 16:07  MarkLeeBYR  阅读(150)  评论(0)    收藏  举报