index
title: 反转链表 date: 2019-08-21T11:00:41+08:00 draft: false categories: offer
题目
输入一个链表,反转链表后,输出新链表的表头。
解题思路
- 三个指针 
public ListNode ReverseList(ListNode head) {
    if (head == null || head.next == null) {
        return head;
    }
    ListNode pre = head, cur = head.next, next;
    pre.next = null;
    while (cur != null) {
        next = cur.next;
        cur.next = pre;
        pre = cur;
        cur = next;
    }
    return pre;
}Last updated
Was this helpful?