[Leetcode] 002. Add Two Numbers
https://leetcode.com/problems/add-two-numbers/
public class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
if(l1 == null) return l2;
if(l2 == null) return l1;
ListNode head = new ListNode(0);
ListNode p = head;
int tmp = 0;
while(l1!=null || l2!=null || tmp!=0) {
if(l1!=null){
tmp += l1.val;
l1 = l1.next;
}
if(l2!=null){
tmp += l2.val;
l2 = l2.next;
}
p.next = new ListNode(tmp%10);
p = p.next;
tmp = tmp/10;
}
return head.next;
}
}
[Leetcode] 002. Add Two Numbers的更多相关文章
- LeetCode #002# Add Two Numbers(js描述)
索引 思路1:基本加法规则 思路2:移花接木法... 问题描述:https://leetcode.com/problems/add-two-numbers/ 思路1:基本加法规则 根据小学学的基本加法 ...
- 【JAVA、C++】LeetCode 002 Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters
LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...
- LeetCode:1. Add Two Numbers
题目: LeetCode:1. Add Two Numbers 描述: Given an array of integers, return indices of the two numbers su ...
- [LeetCode] 445. Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- LeetCode 面试:Add Two Numbers
1 题目 You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- [Leetcode Week15] Add Two Numbers
Add Two Numbers 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/add-two-numbers/description/ Descrip ...
- [LeetCode] 2. Add Two Numbers 两个数字相加 java语言实现 C++语言实现
[LeetCode] Add Two Numbers 两个数字相加 You are given two non-empty linked lists representing two non-ne ...
- [LeetCode] 2. Add Two Numbers 两个数字相加
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
随机推荐
- iOS开发数据库-FMDB
前言 FMDB是以OC的方式封装了SQLite的C语言API,使用起来更加面向对象,省去了很多麻烦.冗余的C语言代码:对比苹果自带的Core Data框架,更加轻量级和灵活:提供了多线程安全的数据库操 ...
- Linux下安装二进制版mysql-8.0.15
1.添加用户## 添加用户组groupadd mysql## 添加用户,指定用户home目录useradd -g mysql mysql -d /data/mysql## 解压下载的mysql二进制包 ...
- hdu-5862 Counting Intersections(线段树+扫描线)
题目链接: Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K ...
- Linux下的Tomcat JVM 调优
1. 适用场景 Tomcat 运行过程遇到Caused by: java.lang.OutOfMemoryError: PermGen space或者java.lang.OutOfMemoryErro ...
- Seal Report_20160923
Seal Report算是报表工具中比较好用的一个,它提供了一个完整的从其他任何数据库产生报表的架构.该产品主要关注于容易安装和报表设计,一旦安装好,报表很快就可以建立并且发布.该组件完全开源,使用C ...
- echarts图表自适应
当页面上只引入一个图表 window.onresize= () =>{ myEchart.resize() } 当引入多个时,上面的方法只会影响最后一个图表 window.addEventLis ...
- BZOJ3674:可持久化并查集加强版
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...
- Spring boot 学习 九
一:经过试验发现,如果使用如下的Controller(@RequestBody), 前台POST的请求body只能是JSON,如果是form-data, X-www-form-urlencoded 或 ...
- static_cast” : 无法从“void (__thiscall CMainFrame::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCmdTarget::* )(NMHDR *,LRESULT
static_cast” : 无法从“void (__thiscall CMainFrame::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCm ...
- FormsAuthentication.Signout不能清楚服务器端cookie
具体信息可以参考文章 https://support.microsoft.com/en-us/help/900111/the-formsauthentication.signout-method-do ...