You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)

Output: 7 -> 0 -> 8

class Solution {
public:
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
int carry = ;
ListNode *l3 = new ListNode();
ListNode *p3 = l3;
while(l1 !=NULL || l2!= NULL){
if(l1 != NULL){
carry += l1->val;
l1 = l1->next;
}
if(l2 != NULL){
carry += l2->val;
l2 = l2->next;
} l3->next = new ListNode(carry % );
carry = carry/;
l3 = l3->next;
}
if(carry == )
l3->next = new ListNode();
return p3->next;
}
};

【leetcode】 Add Two Numbers的更多相关文章

  1. 【leetcode】Add Two Numbers

    题目描述: You are given two linked lists representing two non-negative numbers. The digits are stored in ...

  2. 【题解】【链表】【Leetcode】Add Two Numbers

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  3. 【leetcode】Add Two Numbers(middle) ☆

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  4. 【LeetCode】Add Two Numbers(两数相加)

    这道题是LeetCode里的第2道题. 题目要求: 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将 ...

  5. 【LeetCode445】 Add Two Numbers II★★

    题目描述: 解题思路: 给定两个链表(代表两个非负数),数字的各位以正序存储,将两个代表数字的链表想加获得一个新的链表(代表两数之和). 如(7->2->4->3)(7243) + ...

  6. 【LeetCode】386. Lexicographical Numbers 解题报告(Python)

    [LeetCode]386. Lexicographical Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  7. 【Leetcode】【Medium】Add Two Numbers

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  8. 【链表】Add Two Numbers

    题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...

  9. 【leetcode】1215.Stepping Numbers

    题目如下: A Stepping Number is an integer such that all of its adjacent digits have an absolute differen ...

随机推荐

  1. SE Springer小组之《Spring音乐播放器》需求分析说明书二

    2.1 目标 Spring音乐播放器软件为课程<软件工程>所开发的课程作业,主要意图是为访问计算机中的mp3格式的音频文件,并使其能够完成访问,读取,添加,保存,播放,切换音频文件等功能. ...

  2. 10-Python3从入门到实战—基础之函数

    Python从入门到实战系列--目录 函数的定义 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数的语法 def 函数名(参数列表): 函数体 函数代码块以 def 关键词开头 ...

  3. jQuery(六)

    $下常用方法 $().xxx:只能给jq对象用 $.xxx不仅可以给jq用也可以给原生js用,叫做工具方法 $.type() <script> $(function(){ var a= n ...

  4. PAT 1036 跟奥巴马一起编程

    https://pintia.cn/problem-sets/994805260223102976/problems/994805285812551680 美国总统奥巴马不仅呼吁所有人都学习编程,甚至 ...

  5. Facebook 50%用户是虚假账号?我觉得可以更高!

    0x00 背景 今天下午看新闻时,无意看到一条关于facebook虚假帐号(fake account)消息: 一下子就被这标题吸引了眼球,因为作为一个第三方机构,能够对facebook这样如此海量的帐 ...

  6. VS2012、2013使用Mysql数据库创建EF的AOD.NET实体模型

    VS2012.2013使用Mysql数据库创建EF的AOD.NET实体模型: 1.关闭VS,首先安装mysql-connector-net-6.8.3.(安装后EF创建实体模型时就可以找到Mysql的 ...

  7. mysql复杂查询1

    https://blog.csdn.net/fly910905/article/details/79846949

  8. 机器学习中的降维算法:ISOMAP & MDS

    参见:https://blog.csdn.net/Dark_Scope/article/details/53229427

  9. CPK公式

    CP:Cp = (USL-LSL)/6σ  USL上限值.LSL下限值.σ为产品特性值总体标准差: CPK:Cpk=Cp-|M-μ|/3σ  μ为产品特性值的总体均值,σ为产品特性值总体标准差,M為目 ...

  10. html 響應式web設計

    RWD(響應式web設計)可以根據尺寸大小傳遞網頁,對於平板和移動設備是必須的. <html lang="en-US"> lang表示頁面的主要語言.http://ww ...