Util function recursive solution in Java


  • 0
    R
        public ListNode reverseList(ListNode head) {
            return reverseListUtil(head, null);
        }
        
        private ListNode reverseListUtil(ListNode root, ListNode prev) {
            if (root == null) return prev;
            
            ListNode temp = root.next;
            root.next = prev;
            return reverseListUtil(temp, root);
        }
    

Log in to reply
 

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