# 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. 使用ss命令对tcp连接数和状态的监控性能优化

    之前对tcp的监控采用netstat命令,发现在服务器繁忙的时候效果不理想,这个命令占用大量的cpu有时候高达90%以上,可能会导致业务的不稳定,所以改用ss命令对脚本进行优化 对tcp连接数和状态的 ...

  2. BZOJ3932: [CQOI2015]任务查询系统 主席树

    3932: [CQOI2015]任务查询系统 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 4869  Solved: 1652[Submit][St ...

  3. 牛客寒假算法基础集训营3处女座和小姐姐(三) (数位dp)

    链接:https://ac.nowcoder.com/acm/contest/329/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言52428 ...

  4. poj3349 Snowflake Snow Snowflakes

    吼哇! 关于开散列哈希: 哈希就是把xxx对应到一个数字的东西,可以理解成一个map<xxx, int>(是不是比喻反了) 我们要设计一个函数,这个函数要确保同一个东西能得到相同的函数值( ...

  5. Appium的图像界面浅说

    appium的图形用户界面(GUI) (1)Application中各个项的含义作用: Application Path:填写你需要测试的Android APK的包地址(两种方式:1直接点击Choos ...

  6. 中性SNP的突变年龄评估(estimate the average age of a neutral two-allele polymorphism)

    假设中性突变的频率分别为P和1-P,则其突变年龄为:-4Ne[p*( logep)+(1-p)* loge (1-p)] The average age of a neutral two-allele ...

  7. Hibernate 基础解析(Configuration,SessionFactory,Session,Transaction,Query,Criteria)

    1       框架体系结构 对象关系映射(英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实 现面向对象编程语言里 ...

  8. TODO java-awt中文乱码--疑惑

    参考:http://blog.sina.com.cn/s/blog_025270e90101b1db.html 1.IDE工具是eclipse,检查了编码是UTF-8,控制台中是中文,用awt就会乱码 ...

  9. java 常用的类

    一.日期操作:Calendar类和SimpleDateFormat类 public void Test1() { Calendar calendar=Calendar.getInstance(); S ...

  10. springcloud的turbine集成zookeeper

    1.turbine监控界面显示一直是loading的状态,如何解决 http://blog.didispace.com/spring-cloud-tips-4/ 2.通过追踪turbine的依赖可以看 ...