why cannot we use vector<ListNode *>?


  • 0
    J

    Why cannot we use the vector<ListNode *> here?

    Here is my code:'''
    ListNode* reverseKGroup(ListNode* head, int k) {
    ListNode * temp=head;
    vector<ListNode *> v[k];
    for(int i=0; i<k; i++){
    if(temp == NULL){
    return head;
    }
    v[i]=temp;
    temp=temp->next;
    }
    v[0]->next = reverseKGroup(v[k-1].next, k);
    for(int i=k-1; i>0; i--){
    v[i]->next = v[i-1];
    }

        return v[k-1];
    }
    

    '''
    It gives me the error message of Line 18: no match for 'operator=' (operand types are 'std::vector<ListNode*>' and 'ListNode*')
    If I want this line of code working, does it mean I need to overload the operator in the ListNode struct in order for this line of code to work?


Log in to reply
 

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