002_Add Two Numbers

# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
cur=ListNode(0)
head=cur
temp=0
a=0
while l1 and l2:
a=l1.val+l2.val+temp
temp=0
if a>=10:
temp=a//10
a=a%10
node=ListNode(a)
cur.next=node
l1=l1.next
l2=l2.next
cur=cur.next
while l2:
a=l2.val+temp
temp=0
if a>=10:
temp=a//10
a=a%10
node=ListNode(a)
cur.next=node
l2=l2.next
cur=cur.next
while l1:
a=l1.val+temp
temp=0
if a>=10:
temp=a//10
a=a%10
node=ListNode(a)
cur.next=node
l1=l1.next
cur=cur.next
if temp:
node=ListNode(temp)
cur.next=node
cur=cur.next
return head.next
002_Add Two Numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
随机推荐
- CAN协议,系统结构和帧结构
CAN:Controller Area Network,控制器局域网 是一种能有效支持分布式控制和实时控制的串行通讯网络. CAN-bus: Controller Area Network-bus,控 ...
- redis执行lua文件
1.编写lua文件 还lua表示循环插入1-100的键为1-100值为1-100的键值对到redis中 for i=0,100 do redis.call("set",i,i) e ...
- dbForge Studio for MySQL V8.0 Enterprise
上篇文章:JetBrains全家桶破解思路(最新更新:2018-12-24) 最适合从SQLServer转向MySQL的人使用(用起来基本上差不多) 最适合Net开发人员的MySQL IDE (不装V ...
- Docker中如何删除image(镜像)
原文地址:http://yaxin-cn.github.io/Docker/how-to-delete-a-docker-image.html docker中删除images的命令是docker rm ...
- 洛谷P3620 数据备份
好吧,我一开始说这是个神级数据结构毒瘤题,后来改成神题了. 主要是贪心做法的巧妙转化: 首先发现选择的一对必须相邻,于是我们搞出差分. 然后考虑选取最小值时,最小值两侧的数要么同时选,要么都不选. 然 ...
- 【POJ2226】Muddy Fields
题目大意:给定一个 N*M 的图,图中有一些格子不能被任何东西覆盖,现有一些宽度为 1,长度任意的骨牌覆盖这些可以被覆盖的格子,骨牌之间可以重叠,求将所有可以被覆盖的格子覆盖所需的最小骨牌数是多少. ...
- vue在body上面绑定enter事件
mounted () { this.bodyListener = (e) => { if (e.keyCode === 13 && e.target === document.b ...
- Vue(基础七)_webpack打包工具(续)
---恢复内容开始--- 一.前言 1.webpack-dev-server 2.es6的解析 3.单文件引入 二. ...
- node.js小案例_留言板
一.前言 通过这个案例复习: 1.node.js中模板引擎的使用 2.node.js中的页面跳转和重定向 二.主要内容 1.案列演示: 2.案列源码:https://github.com/45612 ...
- 微信小程序之自定义select下拉选项框组件
知识点:组件,animation,获取当前点击元素的索引与内容 微信小程序中没有select下拉选项框,所以只有自定义.自定义的话,可以选择模板的方式,也可以选择组件的方式来创建. 这次我选择了组件, ...