• + 0 comments

    I guess you were getting a error because you were not setting the prev pointer to null if the head.next == null..

    For example, try this (passes all test cases):

    Node Reverse(Node head) {
        if (head == null) {
            return head;
        }
    
        if (head.next == null) {
            head.prev = null;
            return head;
        }
    
        Node newHead = Reverse(head.next);
        head.next.next = head;
        head.prev = head.next;
        head.next = null;
    
        return newHead;
    }