LeetCode OJ:Add Two Numbers
来源:互联网 发布:linux shellcode 编辑:程序博客网 时间:2024/06/08 18:55
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { ListNode *p=l1,*q=l2,*r; ListNode *nh=new ListNode(0); r=nh; int c=0,s; while(p||q){ s=c; if(p)s+=p->val; if(q)s+=q->val; r->next=new ListNode(s%10); c=s/10; r=r->next; if(p)p=p->next; if(q)q=q->next; } if(c)r->next=new ListNode(c); return nh->next; }};
0 0
- LeetCode OJ:Add Two Numbers
- LeetCode OJ - Add Two Numbers
- LeetCode OJ Add Two Numbers
- LeetCode OJ - Add two Numbers
- LeetCode OJ ----Add Two Numbers
- LeetCode OJ:Add Two Numbers
- Leetcode OJ:Add Two Numbers
- [LeetCode OJ][002]Add Two Numbers
- 【LeetCode OJ 002】Add Two Numbers
- LeetCode OJ #2 Add Two Numbers
- LeetCode OJ 02 Add Two Numbers
- LeetCode OJ : 2 Add Two Numbers
- <LeetCode OJ> 2. Add Two Numbers
- LeetCode OJ 2.Add Two Numbers
- LeetCode OJ 2. Add Two Numbers
- LeetCode OJ(2.Add Two Numbers)
- 三、[LeetCode OJ]Add Two Numbers
- LeetCode OJ-2.Add Two Numbers
- 版本控制SVN
- 分巧克力 - 湖北民族学院提供--【英雄会之高校俱乐部】
- 为什么我们用webdriver而不用selenium IDE呢?
- Theano学习一----安装
- Sublime Text 配置全攻略
- LeetCode OJ:Add Two Numbers
- Codeforces_387A_George and Sleep(模拟)
- Codeforces Round #227 (Div. 2)
- 分享个android源码打包下载地址
- hdu1429(广搜+状态压缩(位压缩))
- ArduinoUNO + Button 的输出(Serial)Demo
- 关于Java中的ServerSocket类与构造服务器的解析
- Theano学习二----numpy
- <MEMORY>Project Euler NO47