clueless coding // TODO: be smarter

LeetCode Reverse Linked List: Java Solution



TL;DR Code Solution


public ListNode reverseList(ListNode head) {

    ListNode prev = null;
    while (head != null) {
        ListNode temp = head.next;
        head.next = prev;
        prev = head;
        head = temp;
    }
    return prev;


}