Incompatible types when assigning to type ‘struct ListNode’ from type ‘struct ListNode *’


  • 0
    Z
    struct ListNode* removeElements(struct ListNode* head, int val) {
    if (head==0) return head;
    struct ListNode* new_head, fhead, node;
    int i=0;
    while (head){
        node=(struct ListNode*)malloc(sizeof(struct ListNode));
        if (head->val==val) head=head->next;
        else if (i==0) {
            node->val=head->val;
            node->next=head->next;
            new_head=head
            fhead=head;
            head=head->next;
        }else{
            fhead->next=node;
            node->val=head->val;
            node->next=head->next
            fhead=node;
            head=head->next
            i++;
        }
    }
    return (new_head);
    

    }

    It says the problem happens at malloc the memory to node


Log in to reply
 

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