# 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的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [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 ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

随机推荐

  1. webpack入门(七) API in LOADERS

    介绍 loaders允许你用require() 预处理文件(preprocess files)或者加载他们,在其他的构建工具中,loaders就是一种像“任务(tasks)”的东西.他提供了一种处理前 ...

  2. 使用Docker Swarm搭建分布式爬虫集群

    https://mp.weixin.qq.com/s?__biz=MzIxMjE5MTE1Nw==&mid=2653195618&idx=2&sn=b7e992da6bd1b2 ...

  3. 洛谷P4769 冒泡排序

    n <= 60w,∑n <= 200w,1s. 解:首先有个全排列 + 树状数组的暴力. 然后有个没有任何规律的状压...首先我想的是按照大小顺序来放数,可以分为确定绝对位置和相对位置两种 ...

  4. A1144. The Missing Number

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

  5. 【洛谷P1601 A+B Problem(高精)】

    题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 ...

  6. 厘摩(centimorgan,cM)到底是啥鬼

    根据维基百科的定义: 厘摩(centimorgan,简写为cM),或称为图距单位(map unit),是遗传连锁中的距离单位,以现代遗传学之父托马斯·亨特·摩尔根的名字命名.1厘摩的定义为两个位点间平 ...

  7. 在windows中把一个文件夹打成war包

    转: 在windows中把一个文件夹打成war包 一般开发打war包时都是用MyEclipse或IntelliJ IDEA等直接导出war文件,这里介绍一种如何把一个文件夹打成war包的方式,如下   ...

  8. css的简单学习笔记

    1.CSS的简介 *css :层叠样式表 **层叠: 一层一层. **样式表: 具有大量的属性和属性值 *使得页面的显示效果更加好. *css将网页内容和显示样式进行分离,提高了显示功能. *css不 ...

  9. python学习笔记—Day1

    1. python使用<变量名>=<表达式>的方式对变量进行赋值 a=1; python中数分为整数和浮点数 字符串的定义一定要用引号,单引号和双引号是等价的 三引号用来输入包 ...

  10. padding内边距

    android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/ac ...