2.2.1Add Two Numbers
来源:互联网 发布:买了域名要主机吗 编辑:程序博客网 时间:2024/06/08 00:27
Notes:
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
Solution: dummy head...
*/
/**
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
Solution: dummy head...
*/
/**
class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { ListNode dummy(0), *cur = &dummy; int carry = 0; while (l1 || l2 || carry) { int sum = carry; if (l1) { sum += l1->val; l1 = l1->next; } if (l2) { sum += l2->val; l2 = l2->next; } carry = sum >= 10 ? 1 : 0; sum %= 10; ListNode *newNode = new ListNode(sum); cur->next = newNode; cur = newNode; } return dummy.next; }};
0 0
- 2.2.1 Add Two Numbers
- 2.2.1Add Two Numbers
- 1 - Add Two Numbers
- Leetcode: Add Two Numbers (1)
- 2.2.1—单链表—Add Two Numbers
- 2.Add Two Numbers(1)
- 算法练习(1):Add Two Numbers
- Add two numbers & Add binary
- LeetCode: Add Two Numbers
- Add Two Numbers
- LeetCode: Add Two Numbers
- [LeetCode]Add Two Numbers
- LeetCode Add Two Numbers
- Leetcode: Add Two Numbers
- Add Two Numbers
- LeetCode : Add Two Numbers
- LeetCode Add Two Numbers
- [LeetCode] Add Two Numbers
- C语言函数名与函数指针详解
- 加载web项目时报的错误:Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modul
- 什么是OBJ文件
- ACM-奇偶数分离
- 关于技术人员的思考
- 2.2.1Add Two Numbers
- Kint,微型、高效的PHP的Debug类库
- cannot be resolved or is not a field错误解决
- Android Studio在Ubuntu的安装过程
- 使用HttpClient4.4 模拟http请求
- spring+jpa 多模块开发+集成测试
- JavaScript函数和事件
- 【他山之石】【Matrix67】 什么是P问题、NP问题和NPC问题
- 支持向量机(四)