add two num
来源:互联网 发布:电脑软件 著作权 专利 编辑:程序博客网 时间:2024/06/05 19:35
# coding:utf-8# 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.## Example## Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)# Output: 7 -> 0 -> 8# Explanation: 342 + 465 = 807.##Definition for singly-linked list.class ListNode(object): def __init__(self, x): self.val = x self.next = Noneclass Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ addition = cur = ListNode(0) carry = 0 if carry or l1 or l2: if l1: carry = carry + l1.val l1 = l1.next if l2: carry = carry + l2.val l2 = l2.next cur.next = ListNode(carry%10) cur = cur.next carry //=10 return addition.next
阅读全文
0 0
- leetcode4-Add Two Num
- 《leetCode》:add two num
- 《leetCode》:add two num
- add two num
- LeetCode #001 Two Num
- LeetCode 1 two num
- leetCode Q1:Two Num(java)
- leetcode 第一题 Two Num java
- Add two numbers & Add binary
- Two Sum & Add Two Numbers
- 题Two--Add Two Numbers
- 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
- 哈理工oj 1942this is bad problom 【基础bfs】
- leetCode-Subarray Product Less Than K
- 软件工程大作业学习记录
- 《深入理解mybatis原理》 MyBatis的架构设计以及实例分析
- JSON
- add two num
- Spring框架开发包下载地址
- EM算法与Baum-Welch算法
- RobocupRescue & Java(2)
- Python:数据库操作模块SQLAlchemy
- demon16.1-16.2
- 关于ext4 buddy bitmap构建分析
- redis-JedisPoolConfig配置
- 第九周项目一__二叉树算法库