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, ...
随机推荐
- AES加密算法-128位高安全,高速度
网上资料显示,下一代加密技术会围绕着AES技术进行.初出茅庐,学习编写了加密代码,如下所示 package com.bao.tools.encryption; import java.security ...
- UVA 10564 十 Paths through the Hourglass
Paths through the Hourglass Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- 【转载】nedmalloc结构分析
原文:nedmalloc结构分析 nedmalloc是一个跨平台的高性能多线程内存分配库,很多库都使用它,例如:OGRE.现在我们来看看nedmalloc的实现 (以WIN32部分为例) 位操作 ...
- Create Hierarchical Tree To Control Records In Oracle Forms
Download Source Code Providing an example form for creating hierarchical trees in Oracle Forms to co ...
- ASP.NET四则运算--工厂模式
这次是在ASP.NET上实现四则运算,之前用策略模式实现了,所以这次想着用工厂模式实现一下. Calculator.cs using System; using System.Collections. ...
- PE结构笔记
提示:前面加*为必须背下来的 DOS头: typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header WORD e_magic; //* Magic n ...
- 《Linux内核设计的艺术》学习笔记(六)执行setup.s
参考资料 1. 8259A可编程中断控制器 jmpi , SETUPSEG // 0x90200 到这里,bootsect.s的执行就算结束了.控制权转移到了setup.s文件的手中. setup程序 ...
- 再学C++之C++中的全部关键字
/*______C++全部关键字___________*/ asm do if return try auto double inline short typedef bool dynamic_cas ...
- ZOJ-3725 Painting Storages 动态规划
题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...
- Java初始化(成员变量)
java尽力保证:所有变量在使用前都能得到恰当的初始化.对于方法的局部变量,java以编译时错误的形式来贯彻这种保证.如下面代码: public class TestJava { void test( ...