Recursive Java solution

  • 2
        public ListNode reverseList(ListNode head) {
            if(head==null|| {
                return head;
            ListNode tail = reverseList(;
   = head;
   = null;
            return tail;

  • 0

    Can you explain the line = head?

  • 0

    ( is the node after head, we want to reverse the direction of ('s next pointer to point back to head, then set head's next pointer to null so that the last node in the reversed list is null terminated.

Log in to reply

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