Linked List
141
Sep 23, 2019

Could anyone please help me out in solving the problem ""Deleting Nth node from last (Linked List Topic)"" ??

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

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){

    int temp,x=0,y=0,i=1,z;
   
 while(l1!=NULL)
 {
     temp=l1->val;
     x=x+temp*i;i*=10;
     l1=l1->next;
 }
i=1;
 while(l2!=NULL)
 {
     temp=l2->val;
     y=y+temp*i;i*=10;
     l2=l2->next;
 }
    z=x+y;
    Head=t;
while(1)
{
    if(z==0)
        return Head;
    else
    {
        t=(struct ListNode *)malloc(sizeof(struct ListNode));
        t->val=z%10;
        z/=10;
        t=t->next;
        
    }
}
    
}```
Comments (1)