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 ...
随机推荐
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- mui侧滑菜单"点击含有mui-action-menu类的控件"无法实现侧滑
.mui-action-menu 标题栏 菜单按钮 指定href="#id"显示与隐藏侧滑菜单 html: <div class="mui-off-canvas-w ...
- 洛谷P1072 Hankson的趣味题
这是个NOIP原题... 题意: 给定 a b c d 求 gcd(a, x) = b && lcm(c, x) = d 的x的个数. 可以发现一个朴素算法是从b到d枚举,期望得分50 ...
- pandas 连接数据库直接查表建立dataframe。loc,sort_values数据清洗操作
#导入pandas import pandas as pd import numpy as np #导入SqlAlchemy from sqlalchemy import create_engine ...
- 对C# .Net4.5异步机制测试(二)——加深印象
public static void Main() { Console.WriteLine(Thread.CurrentThread.ManagedThreadId); In(); Console.W ...
- linux下的crontab安装及简单使用
1.安装 # yum install vixie-cron # yum install crontabs # chkconfig crond on #设为开机启动,先要安装chkconfig(yum ...
- Ajax结合Json进行交互数据(四)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- opencv: 基本知识(二);
1.Mat与IplImage之间的相互转换: //IplImage—>Mat //EXAMPLE: //浅拷贝: IplImage* pBinary=cvLoadImage("c:// ...
- Expected value at 1:0 异常解决方法
有时候自己也很郁闷,明明自己写的是ok的竟然,还报错. 网上查找了这个异常,竟然没有解决方法,后来尝试着去解决,竟然真的解决了. 其实,我又新建一个文件夹,把原先的代码给粘贴复制进去就ok了,其实到现 ...
- 10款Mac上程序员装机必备的开发工具推荐和下载
10款Mac上程序员装机必备的开发工具推荐和下载 使用Mac的用户主要有两大类:设计师和程序员,为各位程序员童鞋推荐10个Mac上非常棒的开发工具和辅助工具,分享软件专题[10款Mac上程序员装机必备 ...