Recursive Method but within single function


  • 3
    D
    public class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode new_head;
            if (head == null)
                return head;
            else {
                new_head = reverseList(head.next);
                if (head.next != null)
                    head.next.next = head;
                else
                    new_head = head;
                head.next = null;
                return new_head;
            }
        }
    }

Log in to reply
 

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