My iterative solution in Java: AC


  • 7
    C

    My solution is below:

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

    Btw, I thought there is no need to judge the NULL Pointer in my solution.


  • 0
    H

    good solution!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.