206. Reverse Linked List - LeetCode

Question

206. Reverse Linked List

Solution

题目大意:对一个链表进行反转

思路:

Java实现:

public ListNode reverseList(ListNode head) {
    ListNode newHead = null;
    while (head != null) {
        ListNode tmp = head.next;
        head.next = newHead;
        newHead = head;
        head = tmp;
    }
    return newHead;
}

猜你喜欢

转载自www.cnblogs.com/okokabcd/p/9320450.html