Add Two Numbers
来源:互联网 发布:西安行知中学是83中吗 编辑:程序博客网 时间:2024/06/10 00:47
题目描述:
You are given two non-empty linked lists representing two non-negative integers. 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.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Subscribe to see which companies asked this question.
public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode fake = new ListNode(0); ListNode t=fake, t1=l1, t2=l2; int a1, a2, r = 0; while (t1!=null || t2!=null || r!=0) { a1 = t1==null ? 0:t1.val; a2 = t2==null ? 0:t2.val; r += a1 + a2; t.next = new ListNode(r%10); r /= 10; t = t.next; if (t1!=null) t1 = t1.next; if (t2!=null) t2 = t2.next; } return fake.next;}
0 0
- 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
- Leetcode : Add Two Numbers
- Add Two Numbers
- 【leetcode】Add Two Numbers
- add two numbers
- Add Two Numbers
- Add Two Numbers
- 初学web前端-20170427
- [安卓基础]学习第三天
- k-近邻
- 使用mave开发mapreduce
- xdoj 1151: 万神的方程
- Add Two Numbers
- 面向对象程序设计与分析--ATM机系统
- OJ中出现WA的小结
- 如何解决ajax跨域问题
- AndroidBitmap图片拷贝
- Dubbo与Zookeeper视频教程分布式架构+第三方支付
- PHP解决网站大数据大流量与高并发
- vb.net 教程 1-5 运算符 2
- Activiti