[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 ...
随机推荐
- oracle数据库如何备份一张表
--用户名:tms--创建表ts_dictionary的备份create table ts_dictionary_20160715 as select * from ts_dictionary; 补充 ...
- Eclipse中导入github上的项目
Eclipse中导入github上的项目 转载至: http://blog.csdn.net/hil2000/article/details/8566456 1.首先在github.com上申请一个账 ...
- 动态IP下群晖搭建DDNS服务
转载地址:https://www.zimrilink.com/share/dsm_aliddns_server.html 通过阿里云API(php)搭建出DDNS动态域名解析服务器;不同的是本文的方法 ...
- (转)C/C++——auto,static,register,extern用法
转自:https://blog.csdn.net/u010757264/article/details/49932829 C++中变量.函数的属性包括数据类型和存储类别.存储类别分为静态存储和动态存储 ...
- PHP读取xml方法介绍
一,什么是xml,xml有什么用途 XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generalized Marku ...
- Chrome检查更新总失败?安装细则讲解
现在 Google Chrome 的稳定版都已经发布 68.0 版本了,我机上还是 54, 本想在线更新一下,结果点击菜单项中的“关于 Google Chrome”后,进入的界面提示“更新失败(错误: ...
- Linux系统上php-cli安装redis扩展
下载 假设已经安装了redis-server,现在我们来安装redis扩展. 下载ZIP包: https://github.com/phpredis/phpredis/tree/master . 解压 ...
- SPOJ CIRU SPOJ VCIRCLE 圆的面积并问题
SPOJ VCIRCLE SPOJ CIRU 两道题都是给出若干圆 就面积并,数据规模和精度要求不同. 求圆面积并有两种常见的方法,一种是Simpson积分,另一种是几何法. 在这里给出几何方法. P ...
- WPF中数据绑定问题
在数据库中字段不区分大小写,可以页面是区分的,一开始以为不区分,可我从数据库查出了数据在前台就是不显示想了半天才发现的. <sdk:DataGrid FrozenColumnCount =&qu ...
- WPF PasswordBox鼠标进入时程序异常退出的解决办法
最近在开发了一个程序中用到了PasswordBox控件,但是在程序给别人用的时候,鼠标一进入控件时程序就异常退出,查了下windows日志,错误显示如下: 应用程序: WpfPasswordTest2 ...