• + 0 comments

    public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) { if (llist == null || llist.next == null) { return llist; }

    // Recursively reverse the rest of the list
    SinglyLinkedListNode newHead = reverse(llist.next);
    
    // Adjust pointers to reverse the list
    llist.next.next = llist; 
    llist.next = null;  
    
    return newHead; 
    }