当前位置: 首页>>代码示例>>C++>>正文


C++ Solution::addTwoNumbers方法代码示例

本文整理汇总了C++中Solution::addTwoNumbers方法的典型用法代码示例。如果您正苦于以下问题:C++ Solution::addTwoNumbers方法的具体用法?C++ Solution::addTwoNumbers怎么用?C++ Solution::addTwoNumbers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Solution的用法示例。


在下文中一共展示了Solution::addTwoNumbers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {

    ListNode *tmp = NULL;

    // construct input list 1
    ListNode *l1 = new ListNode(9);
    tmp = new ListNode(8);
    l1->next = tmp;
    // tmp->next = new ListNode(1);

    // construct input list 2
    ListNode *l2 = new ListNode(1);
    // tmp = new ListNode(9);
    // l2->next = tmp;
    // tmp->next = new ListNode(4);

    Solution soln;
    ListNode *result = soln.addTwoNumbers(l1, l2);

    // test the output
    while(result) {
        int value = result->val;
        result = result->next;
        cout << value << " ";
    }

    cout << endl;

    return 0;
}
开发者ID:alex-liao,项目名称:LeetCode,代码行数:30,代码来源:Add_Two_Numbers.cpp

示例2: main

int main() {
    ListNode* l1 = new ListNode(5);
    ListNode* l2 = new ListNode(5);
    Solution* so = new Solution();
    printResult(so->addTwoNumbers(l1, l2));
    return 0;
}
开发者ID:Daniex,项目名称:OJcode,代码行数:7,代码来源:Solution.cpp

示例3: main

int main() {
	ListNode* a = new ListNode(2);
	ListNode* tmp = a;
	tmp->next = new ListNode(4);
	tmp = tmp->next;
	tmp->next = new ListNode(3);

	ListNode* b = new ListNode(5);
	tmp = b;
	tmp->next = new ListNode(6);
	tmp = tmp->next;
	tmp->next = new ListNode(4);

	Solution s;
	ListNode* result = s.addTwoNumbers(a, b);

	// 查看结果是否正确
	while(result != NULL) {
		cout << result->val << ' ';
		result = result->next;
	}
	cout << endl;

	return 0;
}
开发者ID:Honlan,项目名称:leetcode-c-plus-plus,代码行数:25,代码来源:Add+Two+Numbers.cpp

示例4: main

int main(int argc, char const *argv[])
{
	ListNode* list1;
	ListNode* list2;

	ListNode* l1node1 = new ListNode(2);
	ListNode* l1node2 = new ListNode(4);
	ListNode* l1node3 = new ListNode(3);

	ListNode* l2node1 = new ListNode(5);
	ListNode* l2node2 = new ListNode(6);
	ListNode* l2node3 = new ListNode(3);
	ListNode* l2node4 = new ListNode(6);

	l1node1->next = l1node2;
	l1node2->next = l1node3;

	l2node1->next = l2node2;
	l2node2->next = l2node3;
	l2node3->next = l2node4;

	list1 = l1node1;
	list2 = l2node1;

	Solution s;
	ListNode* psum = s.addTwoNumbers(list1, list2);
	while (psum) {
		std::cout << psum->val << std::endl;
		psum = psum->next;
	}
	return 0;
}
开发者ID:qiannn,项目名称:leetcode,代码行数:32,代码来源:Add+Two+Numbers.cpp

示例5: main

int main()
{
	ListNode *l1 = NULL;
	ListNode *l2 = NULL;

	l1 = new ListNode(2);
	l1->next = new ListNode(4);
	l1->next->next = new ListNode(3);

	l2 = new ListNode(5);
	l2->next = new ListNode(6);
	l2->next->next = new ListNode(4);

	Solution solution;
	ListNode *result = solution.addTwoNumbers(l1, l2);

	while (result != NULL)
	{
		cout << result->val << "->";
		result = result->next;
	}
	
	system("pause");
	return 0;
}
开发者ID:printfchan,项目名称:Leetcode,代码行数:25,代码来源:Add+Two+Numbers.cpp

示例6: main

int main(){
	ListNode *head1 = NULL;
	head1 = new ListNode(0);
	ListNode *p = head1;
	int tt[4] = {1,2,3,4};
	for (int i=0; i!=4; ++i){
		p->next = new ListNode(tt[i]);
		p = p->next; 
	}
	ListNode *head2 = NULL;
	head2 = new ListNode(0);
	ListNode *q = head2;
	int t[3] = {1, 2, 3};
	for (int i=0; i!=3; ++i){
		q->next = new ListNode(t[i]);
		q = q->next; 		
	}
	
	Solution so;
	ListNode *res = NULL;
	res = so.addTwoNumbers(head1->next, head2->next);
	while (res != NULL){
		cout << res->val << endl;
		res = res->next;
	}
	
}
开发者ID:SixerWang,项目名称:leetcode,代码行数:27,代码来源:445.+Add+Two+Numbers+II.cpp

示例7: equalTest

bool equalTest(int v1, int v2)
{
	ListNode *l1 = createList(v1, true);
	ListNode *l2 = createList(v2, true);
	ListNode *lsum = createList(v1 + v2, true);
	return equalList(sln.addTwoNumbers(l1, l2), lsum);
}
开发者ID:banyudu,项目名称:leetcode,代码行数:7,代码来源:test.cpp

示例8: main

int main(int argc, char *argv[]) {
    ListNode a1(0), b1(7), b2(3);
    b1.next = &b2;
    Solution k;
    k.addTwoNumbers(&a1, &b1);
    return 0;
}
开发者ID:KunMZ,项目名称:Practice,代码行数:7,代码来源:Add+Two+Numbers.cpp

示例9: main

int main(int argc, char *argv[]) {
	Solution *s = new Solution;
	
	ListNode *a1 = new ListNode(9);
	ListNode *a2 = new ListNode(4);
	ListNode *a3 = new ListNode(3);
//	a1->next = a2;
//	a2->next = a3;
	
	ListNode *b1 = new ListNode(1);
	ListNode *b2 = new ListNode(9);
	ListNode *b3 = new ListNode(9);
	ListNode *b4 = new ListNode(9);
	ListNode *b5 = new ListNode(9);
	ListNode *b6 = new ListNode(9);
	ListNode *b7 = new ListNode(9);
	ListNode *b8 = new ListNode(9);
	ListNode *b9 = new ListNode(9);
	ListNode *b10 = new ListNode(9);
	b1->next = b2;
	b2->next = b3;
	b3->next = b4;
	b4->next = b5;
	b5->next = b6;
	b6->next = b7;
	b7->next = b8;
	b8->next = b9;
	b9->next = b10;
	
	ListNode *c1 = s->addTwoNumbers(a1, b1);
//	while (c1) {
//		cout << c1->val << endl;
//		c1 = c1->next;
//	}
}
开发者ID:Johncdy,项目名称:LeetCodeSourceCode,代码行数:35,代码来源:Add_Two_Numbers.cpp

示例10: main

int main(int argc, char const *argv[])
{
    ListNode test1(6);
    ListNode test2(2);
    ListNode test3(5);
    ListNode test4(4);
    ListNode test5(5);
    ListNode test6(6);
    ListNode test7(9);

    test1.next = &test2;
    //test2.next = &test3;
    //test3.next = &test4;
    test4.next = &test5;
    test5.next = &test6;
    test6.next = &test7;

    printList(&test1);
    printList(&test4);

    Solution a;

    printList(a.addTwoNumbers(&test1, &test4));

    system("PAUSE");

    return 0;
}
开发者ID:xiaoehaier,项目名称:Leetcode,代码行数:28,代码来源:add-two-numbers.cpp

示例11: main

int main() {
    int t, n;
    Solution s;
    while (cin >> n) {
        ListNode *a = new ListNode(0),*b = new ListNode(0);
        ListNode *pa = a, *pb = b;
        int tmp = n;

        while (n--) {
            cin >> t;
            pa =addValAndCreateNewNode(pa, t);
        }

        while (tmp--) {
            cin >> t;
            pb = addValAndCreateNewNode(pb, t);
        }
        s.addTwoNumbers(a, b);
        while (s != nullptr) {
            cout<<s->val<<endl;
            s = s->next;
        }
    }
    return 0;
}
开发者ID:borisnorm,项目名称:leetcode-1,代码行数:25,代码来源:Two_Numbers_n_II.cpp

示例12: main

int main() {
    ListNode* l1 = initList(9);
    ListNode* l2 = initList(9999991);
    Solution s;
    ListNode* sum = s.addTwoNumbers(l1, l2);
    return 0;
}
开发者ID:zephyrzoom,项目名称:leetcode,代码行数:7,代码来源:2.cpp

示例13: main

int main()
{
	Solution solution;
	ListNode* result;
	ListNode* input1;
	ListNode* input2;
	ListNode* head1;
	ListNode* head2;

	
	//Testcase1:
	head1=new ListNode(9);
	input1=head1;

	head1->next=new ListNode(8);
	head1=head1->next;

	head2=new ListNode(1);
	input2=head2;
	

	/*
	//Testcase2:
	head1=new ListNode(2);
	input1=head1;

	head1->next=new ListNode(4);
	head1=head1->next;

	head1->next=new ListNode(3);
	head1=head1->next;

	head2=new ListNode(5);
	input2=head2;

	head2->next=new ListNode(6);
	head2=head2->next;

	head2->next=new ListNode(4);
	head2=head2->next;
	*/
	
	head1=new ListNode(9);
	input1=head1;

	head1->next=new ListNode(8);
	head1=head1->next;
	
	head2=new ListNode(1); 
	input2=head2;
	//output:[0 9]
	
	result=solution.addTwoNumbers(input1,input2);
	while(result!=NULL)
  	{
    	cout<<result->val<<endl;
    	result=result->next;
    } 

}
开发者ID:ChiaYuLin,项目名称:Leetcode,代码行数:60,代码来源:Solution.cpp

示例14: main

int main(void)
{
    // Build two lists
    ListNode a1(1);
    ListNode a2(2);
    ListNode a3(3);
    a1.next = &a2;
    a2.next = &a3;
    a3.next = NULL;

    ListNode b1(4);
    ListNode b2(5);
    ListNode b3(6);
    b1.next = &b2;
    b2.next = &b3;
    b3.next = NULL;

    ListNode* a = &a1;
    ListNode* b = &b1;

    // Add two lists
    Solution solution;
    ListNode* res = solution.addTwoNumbers(a,b);
    printList(res);





}
开发者ID:ChaunceyKiwi,项目名称:LeetCodeOJ,代码行数:30,代码来源:2-add-two-number.cpp

示例15: main

int main()
{
    ListNode *p1 = new ListNode( 2 );
    ListNode *p2 = new ListNode( 4 );
    ListNode *p3 = new ListNode( 3 );
    p1->next = p2;
    p2->next = p3;


    ListNode *l1 = new ListNode( 5 );
    ListNode *l2 = new ListNode( 6 );
    ListNode *l3 = new ListNode( 6 );
    ListNode *l4 = new ListNode( 9 );
    ListNode *l5 = new ListNode( 9 );

    l1->next = l2;
    l2->next = l3;
    l3->next = l4;
    l4->next = l5;

    ListNode *a1 = new ListNode( 9 );
    ListNode *a2 = new ListNode( 8 );
    ListNode *b1 = new ListNode( 1 );
    ListNode *b2 = new ListNode( 9 );
    a1->next = a2;
    //b1->next = b2;

    Solution sol;
    sol.print_list( sol.addTwoNumbers( a1, b1 ) );

    return 0;
}
开发者ID:cbweixin,项目名称:algorithm-practice,代码行数:32,代码来源:leetcode_add_two_numbers.cpp


注:本文中的Solution::addTwoNumbers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。