[LeeCode]Add Two Numbers
来源:互联网 发布:淘宝vr眼镜宣传视频 编辑:程序博客网 时间:2024/05/21 12:08
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.
class Solution(object): def addTwoNumbers(self, l1, l2): Head = ListNode(0) ans = Head rem = 0 while True: if l1 != None: rem += l1.val l1 = l1.next if l2 != None: rem += l2.val l2 = l2.next ans.val = rem % 10 rem /= 10 if l1 != None or l2 != None or rem != 0: ans.next = ListNode(0) ans = ans.next else: break return Head
阅读全文
0 0
- LeeCode---Add Two Numbers
- [LeeCode]Add Two Numbers
- 2 Add Two Numbers LeeCode
- leecode algo2: Add Two Numbers (Java)
- LeeCode And 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
- LeetCode4: Add Two Numbers
- Leetcode : Add Two Numbers
- MySQL入门——修改数据表3:删除指定表的指定的数据列(字段)
- zookeeper典型应用场景之一:master选举
- Echarts的小例子
- 理解函数式编程
- 文件
- [LeeCode]Add Two Numbers
- 截取
- [分治 + 最短路] BZOJ4456: [Zjoi2016]旅行者
- 布隆过滤器(Bloom Filter)的原理和实现
- Java--this,static,final,const用法
- MySQL入门——修改数据表4:添加主键约束、显示表结构、添加唯一约束、添加外键约束
- List的的另一种实现方法的尝试
- 计蒜之道 第六场
- bzoj4753 最佳团体 树形背包