CODE 126: Add Two Numbers
来源:互联网 发布:三星软件市场 编辑:程序博客网 时间:2024/05/16 11:01
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
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {// Start typing your Java solution below// DO NOT write main() functionListNode cpyl1 = l1;ListNode cpyl2 = l2;int c = 0;while (null != cpyl1 && null != cpyl2) {int tmp = cpyl1.val + cpyl2.val + c;if (tmp > 9) {c = tmp / 10;}cpyl1.val = tmp % 10;cpyl1 = cpyl1.next;cpyl2 = cpyl2.next;}while (cpyl1 != null) {int tmp = cpyl1.val + c;if (tmp > 9) {c = tmp / 10;}cpyl1.val = tmp % 10;cpyl1 = cpyl1.next;}cpyl1 = l1;while (null != cpyl1.next) {cpyl1 = cpyl1.next;}while (cpyl2 != null) {int tmp = cpyl2.val + c;if (tmp > 9) {c = tmp / 10;}cpyl1.next = new ListNode(tmp % 10);cpyl1 = cpyl1.next;cpyl2 = cpyl2.next;}if (c != 0) {cpyl1.next = new ListNode(c);}return l1;}
- CODE 126: Add Two Numbers
- 【Leet Code】Add Two Numbers
- leetcode 日经贴,Cpp code -Add Two Numbers
- Leet Code Medium 2 add two numbers
- leet code 002:Add Two Numbers ???未完成
- Leet Code OJ 2. Add Two Numbers [Difficulty: Medium]
- 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
- LeetCode4: Add Two Numbers
- <input type="text" name="" id=""/>中name和id的区别
- xcdatamodel未被svn同步导致应用内点击图片crash
- 表格 table 的一些属性
- 从电影《乔布斯》看智能家居的创业启示
- 电子信息工程师十年感悟
- CODE 126: Add Two Numbers
- Linux下修改Tomcat默认端口
- 逆向编程培训(第一课)
- .NET/ASP.NET MVC Controller 控制器(二:控制器的创建过程)
- 关于我在做一些项目时候帮助过我的一些资料库的链接
- explain命令和mysql不同存储引擎的区别
- 海量数据面试题整理
- 回文字符串
- 莫虚度,从改变态度开始