Leetcode--Add two number
地址:https://leetcode.com/problems/add-two-numbers/
代码:
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
ListNode *head;
ListNode *current = );
head = current;
;
) {
if (l1 != NULL && l2 != NULL) {
current->val = l1->val + l2->val + temp;
l1 = l1->next;
l2 = l2->next;
} else if (l1 == NULL && l2 == NULL)
current->val = + temp;
else if (l1 == NULL) {
current->val = l2->val + temp;
l2 = l2->next;
} else if (l2 == NULL) {
current->val = l1->val + temp;
l1 = l1->next;
}
temp = ;
) {
current->val %= ;
temp = ;
}
) {
current->next = );
current = current->next;
}
}
return head;
}
};
Leetcode--Add two number的更多相关文章
- [LeetCode] 247. Strobogrammatic Number II 对称数II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [LeetCode] 248. Strobogrammatic Number III 对称数III
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- Leetcode 202 Happy Number 弗洛伊德判环解循环
今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表 ...
- Leetcode 137 Single Number II 仅出现一次的数字
原题地址https://leetcode.com/problems/single-number-ii/ 题目描述Given an array of integers, every element ap ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- LeetCode 260. Single Number III(只出现一次的数字 III)
LeetCode 260. Single Number III(只出现一次的数字 III)
- LeetCode 137. Single Number II(只出现一次的数字 II)
LeetCode 137. Single Number II(只出现一次的数字 II)
- LeetCode 136. Single Number(只出现一次的数字)
LeetCode 136. Single Number(只出现一次的数字)
- LeetCode 137 Single Number II(仅仅出现一次的数字 II)(*)
翻译 给定一个整型数组,除了某个元素外其余的均出现了三次. 找出这个元素. 备注: 你的算法应该是线性时间复杂度. 你能够不用额外的空间来实现它吗? 原文 Given an array of inte ...
- LeetCode——Add Strings
LeetCode--Add Strings Question Given two non-negative integers num1 and num2 represented as string, ...
随机推荐
- axis2通过wsdl生成客户端程序并本地调用
wsdl2java -uri http://10.0.5.12/brm/services/RuleEngine1374389539674484?wsdl -p east.mvc.webservice. ...
- freebsd镜像作用和vmware服务开启
第一个是可以引导的光盘,只能引导系统,通常用于网络安装.基本没用.第二个是系统光盘的第一张.用这张就可以安装一个基本的系统.其他的软件,在系统安装完之后安装.第三个是系统盘的DVD版本.包括的软件比上 ...
- python 自动生成C++代码 (代码生成器)
python 代码自动生成的方法 (代码生成器) 遇到的问题 工作中遇到这么一个事,需要写很多C++的底层数据库类,但这些类大同小异,无非是增删改查,如果人工来写代码,既费力又容易出错:而借用pyth ...
- 用Java集合中的Collections.sort方法对list排序的两种方法
用Collections.sort方法对list排序有两种方法第一种是list中的对象实现Comparable接口,如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- Nexus4_屏幕截图目录
1. /sdcard/Pictures/Screenshots/ 2. 3.
- 11 半联结 & 反联结
半联结 和 反联结是 oracle 优化器能够选择用来在获取信息时应用的两个密切相关的联结方法(实际上是联结方法的选项) 半联结 IN 的半联结 select /* using in */ depar ...
- PHPStorm怎么修改选中的背景颜色呢?
File -> Settings -> editor ->color&fonts->general->下拉框中的selection background-> ...
- Longest Common Prefix
Description: Write a function to find the longest common prefix string amongst an array of strings.( ...
- Mac 实用工具与问题解决
1.在dock上方的一长溜,被我拖成个方块了 删掉里面的字符,然后按esc 即可! 2.FIT输入法(Fun Input Toy),是苹果操作系统OS X上的免费中文输入法,支持全拼/双拼/全双混拼, ...
- 2015苹果WWDC开发者大会
2015苹果WWDC开发者大会 (1)本届主题为“the epicenter of change(变革的中心)” (2)iOS 9.OS X.watchOS三款重要系统更新以及其他服务 (3)iOS ...