Java, 1ms, 6 lines of code, using recursion


  • 5
    Y
    public ListNode reverseList(ListNode head) {
    		if (head == null)  return null;
            if (head.next == null) return head;
            ListNode node = reverseList(head.next);
            head.next.next = head;
            head.next = null;
            return node;
    }

Log in to reply
 

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