206. Reverse Linked List - LeetCode

Question

206. Reverse Linked Listjava

Solution

題目大意:對一個鏈表進行反轉code

思路:ip

Java實現:leetcode

public ListNode reverseList(ListNode head) {
    ListNode newHead = null;
    while (head != null) {
        ListNode tmp = head.next;
        head.next = newHead;
        newHead = head;
        head = tmp;
    }
    return newHead;
}
相關文章
相關標籤/搜索