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, ...
随机推荐
- C#中关键字ref修饰类对象或结构体[转]
using System; using System.Collections.Generic; using System.Text; namespace CSharpTest { struct Dog ...
- 关于cookie的清除
关于cookie的清除 设置cookie时若指定了目录,那么在删除cookie时也必须指定相同的目录,如此才可以删除之前设置的cookie的值!!!!!!!!!
- Django的Many-to-Many(多对多)模型
Django的Many-to-Many(多对多)模型 日期:2012-05-05 | 来源:未知 | 作者:redice | 人围观 | 1 人鼓掌了! 鲲鹏Web数据抓取 - 专业Web ...
- Spring整合Hibernate图文步骤
首先建立java Project工程 点击Finish完成 添加Hibernate和Spring所需要的jar包还有Mysql连接的jar包 创建Dao层,Dao层实现,Model层,Service层 ...
- 头文件为什么要加#ifndef #define #endif
#ifndef 在头文件中的作用 在一个大的软件工程里面,可能会有多个文件同时包含一个头文件,当这些文件编译链接成一个可执行文件时 ,就会出现大量“重定义”的错误.在头文件中实用#ifndef #de ...
- C# 模拟鼠标写字
经常看到别人拿个四四方方的写字板用笔写字,用C#其实也可以实现,大致思路就是处理鼠标的坐标和Graphics, 代码如下: 首先声明两个全局变量 bool isMouseDown = false; P ...
- Python基础学习笔记(九)常用数据类型转换函数
参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-variable-types.html 3. http://www ...
- 2013 Multi-University Training Contest 10
HDU-4698 Counting 题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax& ...
- MyEclipse + Tomcat 热部署问题
myEclipse设置对应的tomcat时,只需要在jdk的Optional Java VM arguments中添加如下设置: -Xms256m -Xmx512m-Dcom.sun.manageme ...
- nodejs学习笔记<三>关于路由(url)
在网站开发中,路由的设置非常关键.nodejs对路由处理封装了一个比较全面的模块. 来认识下url模块 1)在命令行(cmd)可以直接 node —> url 可直接查看url模块的所有方法. ...