Beispiel #1
0
    ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
		int len1 = 0, len2 = 0;
		ListNode *p1 = l1, *p2 = l2;
		while(p1){
			len1++;
			p1 = p1->next;
		}
		while(p2){
			len2++;
			p2 = p2->next;
		}
		if(len1 < len2)
			return addTwoNumbers(l2, l1);
		ListNode *newl2 = new ListNode(0), *p = newl2;
		for(int i = 0; i < len1-len2; ++ i){
			p->next = new ListNode(0);
			p = p->next;
		}
		p->next = l2;
		int carry = 0;
		ListNode *res = addTwoNumbers(l1, newl2->next, carry);
		if(carry){
			ListNode *carryNode = new ListNode(carry);
			carryNode->next = res;
			return carryNode;
		}else
			return res;
		return NULL;
    }
Beispiel #2
0
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
{
    if (l1 == NULL) {
        return l2;
    }
    else if (l2 == NULL) {
        return l1;
    }

    struct ListNode *p1;
    struct ListNode *p2;
    struct ListNode *head = l1;

    int sum;
    int quotient = 0;    
    while ((l1 != NULL) && (l2 != NULL)) {
        sum = l1->val + l2->val;
        l1->val = (sum + quotient)%10;
        quotient = (sum + quotient)/10;

        p1 = l1;
        p2 = l2;
        p2->val = quotient;
        
        l1 = l1->next;
        l2 = l2->next;
    }

    if ((l1 == NULL) && (l2 == NULL)) {
        if (0 != quotient) {
            p1->next = p2;
        }
    }
    if (l1 == NULL) {
        if (0 != quotient) {
            if (p2 != NULL) {
                p2->next = NULL;
                p1->next = addTwoNumbers(p2, l2);
            }
        }
        else {
            p1->next = l2;
        }
    }
    else {
        if (0 != quotient) {
            p1->next = addTwoNumbers(p2, p1->next);
        }
    }

    return head;
}
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        bool tag = 0;	//进位标志1
        ListNode* result = new ListNode(9);  //初始设置
		ListNode* end = result;
		while(!(l1==NULL || l2==NULL))
		{
			int temp = l1 -> val + l2 -> val + tag;
			tag = 0;
			if (temp > 9)
			{
				temp = temp % 10;
				tag = 1;
			}
			ListNode* tmplist = new ListNode(temp);
			end -> next = tmplist;
			end = end -> next;
			l1 = l1 -> next;
			l2 = l2 -> next;
		}
		if(!l1&&l2)
		{
			if(tag == 0)
				end -> next = l2;
			else
			{
				ListNode* tag1 = new ListNode(1);
				end -> next = addTwoNumbers(tag1, l2);
				tag = 0;
			}
		
		}
		if(l1&&!l2)
		{
			if(tag == 0)
				end -> next = l1;
			else
			{
				ListNode* tag1 = new ListNode(1);
				end -> next = addTwoNumbers(tag1, l1);
				tag = 0;
			}
		}
		else if(tag == 1)
		{
			ListNode* tag1 = new ListNode(1);
			end -> next = tag1;
		}
		return result -> next;
    }
Beispiel #4
0
main()
{
int iResult;
//int iResult2;
iResult = addTwoNumbers(5,5);
//iResult2 = subtractTwoNumbers (9, 6);
}
Beispiel #5
0
int main()
{
    int first, second, sum;
    printf("Enter a first number: " );
    scanf("%d", &first);
    printf("Enter a second number: " );
    scanf("%d", &second);

    addTwoNumbers(&first, &second, &sum);
    printf("The sum is: %d\n", sum);



// Pass by copy
/*int addTwoNumbers(int a, int b)
{
    int sum = a + b;
    return sum;
}


int main()
{
    int first, second;
    printf("Enter a first number: " );
    scanf("%d", &first);
    printf("Enter a second number: " );
    scanf("%d", &second);

    int sum = addTwoNumbers(first, second);
    printf("The sum is: %d\n", sum);*/

    return 0;
}
	ListNode *addTwoNumbers(ListNode *l1, int n1, ListNode *l2, int n2){
		if (n1 < n2){
			return addTwoNumbers(l2, n2, l1, n1);
		}

		ListNode *cur1 = l1, *cur2 = l2;
		ListNode *prev = nullptr;

		int overflow = 0;
		while (cur1 || cur2)
		{
			int val1 = cur1->val, val2 = cur2 ? cur2->val : 0;
			cur1->val = (val1 + val2 + overflow) % 10;
			overflow = (val1 + val2 + overflow) / 10;
			if (cur1->next == nullptr){
				prev = cur1;
			}
			cur1 = cur1->next;
			cur2 = cur2 ? cur2->next : nullptr;
		}
		if (overflow){
			prev->next = new ListNode(overflow);
		}

		return l1;
	}
Beispiel #7
0
//测试
void addTwoNumbersMain()
{
    struct ListNode l1[]={ {7, NULL}, {5, NULL}, {1, NULL}, {2, NULL}, {3, NULL} };
    struct ListNode l2[]={ {1, NULL}, {0, NULL}, {9, NULL}, {7, NULL}, {6, NULL}, {9, NULL}, {4, NULL} };
    int len1;
    int len2;
    GET_ARRAY_LEN(l1, len1);
    GET_ARRAY_LEN(l2, len2);

    int i = 0;
    for(i = 0; i<len1-1; i++)
    {
        l1[i].next = &l1[i+1];
    }
    for(i = 0; i<len2-1; i++)
    {
        l2[i].next = &l2[i+1];
    }

    struct ListNode *result = addTwoNumbers(l1, l2);

    while(result)
    {
        printf("%d", result->val);
        result = result->next;
    }
}
Beispiel #8
0
int main(int argc, char** argv)
{
  struct ListNode* a0 = malloc(sizeof(struct ListNode));
  struct ListNode* a1 = malloc(sizeof(struct ListNode));
  struct ListNode* a2 = malloc(sizeof(struct ListNode));
  struct ListNode* b0 = malloc(sizeof(struct ListNode));
  struct ListNode* b1 = malloc(sizeof(struct ListNode));
  struct ListNode* b2 = malloc(sizeof(struct ListNode));

  a0->val = 2;
  a1->val = 4;
  a2->val = 3;

  b0->val = 5;
  b1->val = 6;
  b2->val = 4;

  a0->next = a1;
  a1->next = a2;
  a2->next = NULL;

  b0->next = b1;
  b1->next = b2;
  b2->next = NULL;

  struct ListNode* rtn = addTwoNumbers(a0, b0);
  struct ListNode* temp = rtn;
  while (temp != NULL)
  {
    printf("%d\n", temp->val);
    temp = temp->next;
  }
  return 0;
}
Beispiel #9
0
int main() {
    struct ListNode *l1, *l2,* tl1, *tl2, *inTemp;
    char input;
    l1 = NULL;
    while(1){
            input = getchar();
            if(input == '+')
                break;
            if(input >= '0' && input <= '9'){
                    input -=48;
                    inTemp = (struct ListNode*)malloc(sizeof(struct ListNode));
                    inTemp->val = input;
                    inTemp->next=NULL;
                    if(l1 == NULL){
                        l1 = tl1 = inTemp;
                    }else{
                        tl1->next = inTemp;
                        tl1=inTemp;                        
                    }
                    //printf("hehe: %d\n",inTemp->val);        
            }else{
                continue;
            }            
    }
    //do not forget this why??
    //gcc -g 2.c to debug;
    inTemp = NULL;
    l2=NULL;    
    while(1){
            input = getchar();
            if(input == ')')
                break;
            if(input >= '0' && input <= '9'){
                    input -=48;
                    inTemp = (struct ListNode*)malloc(sizeof(struct ListNode));
                    inTemp->val = input;
                    inTemp->next=NULL;
                    if(l2 == NULL){
                        l2 = tl2 = inTemp;
                    }else{
                        tl2->next = inTemp;
                        tl2=inTemp;                        
                    }
                    //printf("%d\n",inTemp->val);
            }else{
                continue;
            }

    }
    getchar();

    struct ListNode * re;
    re  = addTwoNumbers(l1,l2);

    printList(l1);
    printList(l2);
    printList(re);
    return 0;
}
Beispiel #10
0
int main() {
  ListNode *i1 = new ListNode(1);
  ListNode *i2 = new ListNode(1);

  addTwoNumbers(i1, i2);
  
  return 0;
}  
 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2, int carry) {
     if (l1 == NULL && l2 == NULL){
         return (carry == 0) ? NULL : new ListNode(carry);
     }
     int sum = getVal(l1) + getVal(l2) + carry;
     ListNode *l3 = new ListNode(sum % 10);
     l3->next = addTwoNumbers(toNext(l1), toNext(l2), sum / 10);
     return l3;
 }
Beispiel #12
0
int main(int argc, const char* argv[])
{
	//function implementation
	int ans  = addTwoNumbers(atoi(argv[1]),atoi(argv[2]));
	
	printf("Answer is: %d", ans);
	puts("\n");
	
	return 0;
}
Beispiel #13
0
void SampleToolsPlugin::initializePlugin()
{
    // Create our Add Two Numbers action

    mAddTwoNumbersAction = new QAction(Core::mainWindow());

    // A connection to handle our Add Two Numbers action

    connect(mAddTwoNumbersAction, SIGNAL(triggered()),
            this, SLOT(addTwoNumbers()));
}
Beispiel #14
0
    ListNode *addTwoNumbers(ListNode *l1, ListNode *l2, int &carry) {
		if(!l1&&!l2){
			carry = 0;
			return NULL;
		}
		int c;
		ListNode *prev = addTwoNumbers(l1->next, l2->next, c);
		int val = c + l1->val + l2->val;
		carry = val/10;
		val%=10;
		ListNode *res = new ListNode(val);
		res->next = prev;
		return res;
	}
Beispiel #15
0
		ListNode *addTwoNumbers(ListNode *l1, ListNode *l2)
		{
			if (nullptr == l1)
			  return l2;
			if (nullptr == l2)
			  return l1;
			int iOverflow = 0;
			ListNode *p1 = l1, *p2 = l2, *p3 = l1;
			while (p1 && p2)
			{
				p1->val = p1->val + p2->val + iOverflow;
				iOverflow = p1->val/10;
				if (iOverflow)
				  p1->val %=10;
				p3 = p1;
				p1 = p1->next;
				p2 = p2->next;
			}
			if (!iOverflow)
			{
				//p1不为空不需处理
				if (p2)
				  p3->next = p2;
			}
			else if (iOverflow)
			{
				ListNode *ln = new ListNode(iOverflow);
				assert(ln);
				if (nullptr == p1)
				{
					p3->next = addTwoNumbers(ln, p2);
				}
				else
				  p3->next = addTwoNumbers(ln, p1);
			}
			return l1;
		}
Beispiel #16
0
int main() {
	int a[] = { 2, 4, 5, 3 };
	int b[] = { 5, 6, 4 };
	ListNode *l1, *l2, *ans, *cur;
	initList(&l1, a, sizeof(a) / sizeof(int));
	initList(&l2, b, sizeof(b) / sizeof(int));
	ans = addTwoNumbers(l1, l2);
	for (cur = ans; cur->next != NULL; cur = cur->next) {
		printf("%d -> ", cur->val);
	}
	printf("%d\n", cur->val);
	freeList(&ans);
	freeList(&l1);
	freeList(&l2);
	return 0;
}
Beispiel #17
0
int main(void) {
	struct ListNode a;
	struct ListNode b;

	a.val = 0;
	a.next = NULL;
	b.val = 1; 
	b.next = NULL;

	struct ListNode* sum = addTwoNumbers(&a, &b);
	while (sum) {
		printf("%d ", sum->val);
		sum = sum->next;
	}
	return 0;
}
Beispiel #18
0
 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2, int carry = 0) {
 	if(NULL == l1 && NULL == l2) {
 		return ((carry==0)?(NULL):(new ListNode(carry)));
 	}
 	else if(NULL == l1) {
 		return addNumber(l2, carry);
 	}
 	else if(NULL == l2) {
 		return addNumber(l1, carry);
 	}
 	else {
 		ListNode* ret = new ListNode((l1->val + l2->val + carry)%10);
 		ret->next = addTwoNumbers(l1->next, l2->next, (l1->val + l2->val + carry)/10);
 		return ret;
 	}
 }
Beispiel #19
0
int main(int argc, const char* argv[])
{
	int myints1[] = {5, 0, 0};
	vector<int> v1(myints1, myints1+sizeof(myints1)/sizeof(int));
	ListNode *l1 = new ListNode(v1);
	int myints2[] = {5, 0, 0};
	vector<int> v2(myints2, myints2+sizeof(myints2)/sizeof(int));
	ListNode *l2 = new ListNode(v2);
	ListNode *res = addTwoNumbers(l1, l2);
	l1->display();
	l2->display();
	res->display();
	delete l1;
	delete l2;
	delete res;
	return 0;
}
Beispiel #20
0
	ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
		ListNode *cur = l1;
		int n1 = 0, n2 = 0;
		while (cur)
		{
			cur = cur->next;
			n1++;
		}

		cur = l2;
		while (cur)
		{
			cur = cur->next;
			n2++;
		}
		return addTwoNumbers(l1, n1, l2, n2);
	}
Beispiel #21
0
void testAddTowNumber(void) {
//    int input1[] = {2,4,3,-1};
//    int input2[] = {5,6,4,-1};
    int input1[] = {5,-1};
    int input2[] = {5,-1};

    struct ListNode *inputList1 = createByArray(input1);
    struct ListNode *inputList2 = createByArray(input2);
    showListNode(inputList1);
    putchar('\n');
    showListNode(inputList2);
    putchar('\n');

    
    struct ListNode *result = addTwoNumbers(inputList1, inputList2);
    showListNode(result);
    
}
Beispiel #22
0
void fuckingtest(){
    int TEST_TIMES = 100000;
    srand(time(0));
    for(int i=0; i<TEST_TIMES; i++){
        int a = rand() % 100000000, b = rand() % 100000000;
        //a = 1, b = 99999;
        int sum = a + b;
        ListNode* l1 = createList(a);
        ListNode* l2 = createList(b);
        //printList(l1);
        //printList(l2);
        //printList(addList(l1, l2));
        ListNode* res = addTwoNumbers(l1, l2);
        int sum2 = parseList(res);
        if(sum != sum2){
            printf("F**K!%d a=%d, b=%d, sum1 = %d, sum2 = %d ", i, a, b,sum, sum2);
            break;
        }
    }
    printf("F*****G OK!!!");
}
Beispiel #23
0
void AddTwoNumbers::TestClass()
{
    ListNode *l1;
    ListNode *l2;
    l1=(ListNode*)malloc(sizeof(ListNode));
    l2=(ListNode*)malloc(sizeof(ListNode));

    int A1[3]= {2,4,9};
    int A2[3]= {5,6,4};
    l1->val=A1[0];
    l2->val=A2[0];
    l1->next=NULL;
    l2->next=NULL;

    ListNode *p,*q;
    p=l1;
    q=l2;
    for (int i=1; i<3; i++)
    {
        ListNode *res;
        res=(ListNode*)malloc(sizeof(ListNode));
        res->val=A1[i];
        res->next=NULL;
        p->next=res;
        p=p->next;
    }
    for(int i=1; i<2; i++)
    {
        ListNode *res2;
        res2=(ListNode*)malloc(sizeof(ListNode));
        res2->val=A2[i];
        res2->next=NULL;
        q->next=res2;
        q=q->next;
    }

    p=l1;
    q=l2;
    addTwoNumbers(l1,l2);
}
Beispiel #24
0
void main()
{
	struct ListNode a;
	a.val = 1;
	a.next = NULL;


	struct ListNode c;
	c.val = 9;
	c.next = NULL;

	struct ListNode b;
	b.val = 1;
	b.next = &c;

	struct ListNode* sum = addTwoNumbers(&a,&b);
	while(sum)
	{
		printf("%d,", sum->val);
		sum = sum->next;
	}
	puts("");
	return ;
}
Beispiel #25
0
int main(void)
{
	listNode* l13 = makeNewNode(3, NULL);
	listNode* l12 = makeNewNode(4, l13);
	listNode* l1 = makeNewNode(2, l12);
	listNode* l23 = makeNewNode(4, NULL);
	listNode* l22 = makeNewNode(6, l23);
	listNode* l2 = makeNewNode(5, l22);
	listNode* output = addTwoNumbers(l1, l2);
	listNode* p = output;
	while (p->next != 0)
	{
		printf("%d->", p->val);
		p = p->next;
	}
	printf("%d\n",p->val);
	while (output->next != 0)
	{
		p = output;
		output = output->next;
		free(p);
	}
	return 0;
}
Beispiel #26
0
int main()
{
    int i = 0;
    int Array1[] = {0,5,3,0,3,2,2,0,2};
    int Array2[] = {8,0,2,8,9,6,2,1,9};
    printf("Array1: ");
    print(Array1);
    puts("");
    printf("Array2: ");
    print(Array2);
    puts("");

    struct ListNode *listnode1 = (struct ListNode *) calloc (1, sizeof(struct ListNode));
    struct ListNode *listnode2 = (struct ListNode *) calloc (1, sizeof(struct ListNode));

    if (!listnode1 || !listnode2) {
        return -1;
    }

    listnode1->val = 0;
    listnode2->val = 0;
    listnode1->next = NULL;
    listnode2->next = NULL;

    /*尾插法建立单链表*/
    struct ListNode *r = listnode1;
    for (i=0; i<LENGTH; i++) {
        struct ListNode *listnode = (struct ListNode *) malloc (sizeof(struct ListNode));
        listnode->val = Array1[i];
        listnode->next = r->next;
        r->next = listnode;
        r = r->next;
    }

    r = listnode2;
    for (i=0; i<LENGTH; i++) {
        struct ListNode *listnode = (struct ListNode *) malloc (sizeof(struct ListNode));
        listnode->val = Array2[i];
        listnode->next = r->next;
        r->next = listnode;
        r = r->next;
    }

    i = 0;
    struct ListNode *tmp = listnode1->next;
    printf("源链表1:\n");
    while(tmp) {
        printf("listnode1[%d] = %d\n", i, tmp->val);
        i++;
        tmp = tmp->next; 
    }
    i = 0;
    tmp = listnode2->next;
    printf("源链表2:\n");

    while(tmp) {
        printf("listnode2[%d] = %d\n", i, tmp->val);
        i++;
        tmp = tmp->next; 
    }

    struct ListNode *res = addTwoNumbers(listnode1->next, listnode2->next);

    tmp = res;

    i = 0;
    while (tmp) {
        printf("after calculating: \n");
        printf("res[%d] = %d\n", i, tmp->val);
        i++;
        tmp = tmp->next;
    }
    return 0;

}
main()
{
	int selection = 0;
	int c=0;
	
	do //begin do while
	{
		float x=0;
		float y=0;
		float fResult=0;
		int ix=0;
		int iy=0;
		int iResult=0;
		int factor=0;
		int temp=0;
		int*pResult=0;
	printf("\nCalculator Menu\n\n");
	printf("[1]\tAddition\n");
	printf("[2]\tSubtraction\n");
	printf("[3]\tMultiplication\n");
	printf("[4]\tDivision\n");
	printf("[5]\tModulus (Integers Only)\n");
	printf("[6]\tPrime Test (Integers Only)\n");
	printf("[7]\tFactorial (Integers Only)\n");
	printf("[8]\tPower\n");
	printf("[9]\tFibonacci Sequence\n");
	printf("[0]\tExit\n");
		
	printf("\nPlease Select an option: ");
	scanf("%d",&selection);
	
	switch(selection)
	{
		case 1://Addition
			{
				printf("\nYou have selected \"Addition\"");
				printf("\nx + y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				addTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 2://Subtraction
			{
				printf("\nYou have selected \"Subtraction\"");
				printf("\nx - y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				subTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 3://Multiplication
			{
				printf("\nYou have selected \"Multiplication\"");
				printf("\nx * y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				multTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 4://Division
			{
				printf("\nYou have selected \"Division\"");
				printf("\nx // y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				divTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 5://Modulus
			{
				printf("\nYou have selected \"Modulus\"");
				printf("\nx %% y = ?");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);
				printf("\nPlease input an integer value for \"y\": ");
				scanf("%d",&iy);
				modTwoNumbers(ix,iy);
				printf("\n-------------------------------------------");
				break;
			}
		case 6://Prime Test
			{
				printf("\nYou have selected \"Prime Test\"");
				printf("\nTest if x is prime");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);
				primeFactor(ix);
				printf("\n-------------------------------------------");
				break;
			}
			case 7://Factorial
			{
				printf("\nYou have selected \"Factorial\"");
				printf("\nx!");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);	
				factorial(ix);
				printf("\n-------------------------------------------");
				break;	
					
			}
			case 8://Power
			{
				printf("\nYou have selected \"Power\"");
				printf("\nx to the power of y");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("%f",x);
				printf("\nPlease input an integer value for \"y\": ");
				scanf("%d",&ix);
				powerOf(x,ix);
				printf("\n-------------------------------------------");
				break;
			}
			case 9://Fibonacci
			{
				printf("\nYou have selected \"Fibonacci Sequence\"");
				printf("\nDisplay the Fibonacci Sequence up to and including n=x");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);	
				fibonacci(ix);
				printf("\n-------------------------------------------");
				break;				
			}
			case 0://Exit
			{
				printf("\nHave a nice day!");
				printf("\n-------------------------------------------");
				break;
			}
			default://Invalid
			{
				printf("\nInvalid Option!\nPlease sekect a valid option!");
				printf("\n-------------------------------------------");
				break;
			}
	}
	
	
	
	}while(selection!=0);
	
	return 0;
}
 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
     return addTwoNumbers(l1, l2, 0);
 }
Beispiel #29
0
    ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        
		if (l1 == NULL && l2 == NULL)
		{
			//empty lists
			return NULL;
		}
		
		int tmp = 0;
		ListNode *l1Cur = l1;
		ListNode *l1Pre = l1;
		ListNode *l2Cur = l2;
		ListNode *l2Pre = l2;
		
		while (l1Cur != NULL && l2Cur != NULL)
		{
			l1Cur->val += l2Cur->val + tmp;
			if (l1Cur->val >= 10)
			{
				tmp = 1;
				l1Cur->val -= 10;
			}
			else
			{
				tmp = 0;
			}
			l2Cur->val = l1Cur->val;
			
			l1Pre = l1Cur;
			l1Cur = l1Cur->next;
			l2Pre = l2Cur;
			l2Cur = l2Cur->next;
		}
		
		if (l1Cur == NULL && l2Cur == NULL)
		{
			// lists with same lenght, prefer l1
			if (tmp == 1)
			{
				// with a carry
				ListNode *newNode = new ListNode(1);
				l1Pre->next = newNode;
			}
			return l1;
		}
		else if (l1Cur == NULL)
		{
			// l2 is longer
			if (tmp == 1)
			{
				ListNode *newNode = new ListNode(1);
				addTwoNumbers(l2Cur, newNode);
				delete newNode;
			}
			return l2;
		}
		else
		{
			// l1 is longer
			if (tmp == 1)
			{
				ListNode *newNode = new ListNode(1);
				addTwoNumbers(l1Cur, newNode);
				delete newNode;
			}
			return l1;	
		}
		
    }