time limit exceeded!


  • 0
    A

    ''' struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
    typedef struct ListNode node;
    int i=0,j=0,num1,num2,k=0,sum,reverse;
    node* l3;
    while(l1)
    {num1=l1->valpow(10,i);
    i++;
    l1=l1->next;
    }
    while(l2)
    {num2=l2->val
    pow(10,j);
    j++;
    l2=l2->next;
    }
    sum=num1+num2;
    do
    {j=sum/10;
    k++;
    }while(j!=0);

    while(sum!=0)
    {reverse=reverse*10;
    reverse=reverse+sum%10;
    sum=sum/10;
    }
    while(k>0)
    { l3=(node *)malloc(sizeof(node));
    l3->val=reverse/pow(10,k-1);

     if(k==1)
     l3->next=NULL;
      
     else
      l3=l3->next;
      k--;    
     }
    
    return l3;
    

    } '''


Log in to reply
 

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