When I work out in Code blocks I m getting right But here getting Warning as Incompatible assignment of pointer type


  • 0
    N

    /**

    • Definition for singly-linked list.
    • struct ListNode {
    • int val;
      
    • struct ListNode *next;
      
    • };
      */

    struct ListNode * reverse(struct ListNode **l)
    {
    struct node lcopy=NULL;
    lcopy=(struct ListNode
    )malloc(sizeof(struct ListNode));
    lcopy=*l;

    if (!lcopy)
        return NULL;
    struct ListNode *prev=NULL;
    struct ListNode * temp=NULL;
    while(lcopy)
    {
        temp=lcopy->next;
        lcopy->next=prev;
        prev=lcopy;
        lcopy=temp;
    }
    

    *l=prev;
    return *l;

    };

    struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
    {
    struct ListNode * l1copy=l1;
    struct ListNode l2copy=l2;
    struct ListNode * result=NULL;
    result=(struct ListNode
    )malloc(sizeof(struct ListNode));
    struct ListNode *resultcopy=NULL;
    resultcopy=result;

    if(!l1 && !l2)return NULL;
    if(!l1)return l2;
    if(!l2)return l1;
    
    l1copy=reverse(&l1copy);
    l2copy=reverse(&l2copy);
    
    int carry=0;
    int val;
    while(l1copy && l2copy)
    {
       
        if(val>9)
        {
            result->val=val%10;
            carry=1;
        }
        else{
            carry=0;
            result->val=val;
        }
    
        if(l1copy->next && l2copy->next)
        {
            l1copy=l1copy->next;
            l2copy=l2copy->next;
    
    
            struct ListNode* newnode=(struct ListNode*)malloc(sizeof(struct ListNode));
            result->next=newnode;
    
        result=result->next;
        }
        else
            break;
    }
     if(carry=1)
    {
                    struct node* newnode=(struct node*)malloc(sizeof(struct node));
                                result->next=newnode;
        result->next->data=1;
    }
    
    
    resultcopy=reverse(&resultcopy);
    return resultcopy;
    

    };


  • 0
    K

    In reverse function, you need to return I not *I


Log in to reply
 

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