地址: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的更多相关文章

  1. [LeetCode] 247. Strobogrammatic Number II 对称数II

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  2. [LeetCode] 248. Strobogrammatic Number III 对称数III

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  3. Leetcode 202 Happy Number 弗洛伊德判环解循环

    今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表 ...

  4. Leetcode 137 Single Number II 仅出现一次的数字

    原题地址https://leetcode.com/problems/single-number-ii/ 题目描述Given an array of integers, every element ap ...

  5. leetcode 136 Single Number, 260 Single Number III

    leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...

  6. LeetCode 260. Single Number III(只出现一次的数字 III)

    LeetCode 260. Single Number III(只出现一次的数字 III)

  7. LeetCode 137. Single Number II(只出现一次的数字 II)

    LeetCode 137. Single Number II(只出现一次的数字 II)

  8. LeetCode 136. Single Number(只出现一次的数字)

    LeetCode 136. Single Number(只出现一次的数字)

  9. LeetCode 137 Single Number II(仅仅出现一次的数字 II)(*)

    翻译 给定一个整型数组,除了某个元素外其余的均出现了三次. 找出这个元素. 备注: 你的算法应该是线性时间复杂度. 你能够不用额外的空间来实现它吗? 原文 Given an array of inte ...

  10. LeetCode——Add Strings

    LeetCode--Add Strings Question Given two non-negative integers num1 and num2 represented as string, ...

随机推荐

  1. C#中关键字ref修饰类对象或结构体[转]

    using System; using System.Collections.Generic; using System.Text; namespace CSharpTest { struct Dog ...

  2. 关于cookie的清除

    关于cookie的清除     设置cookie时若指定了目录,那么在删除cookie时也必须指定相同的目录,如此才可以删除之前设置的cookie的值!!!!!!!!!

  3. Django的Many-to-Many(多对多)模型

      Django的Many-to-Many(多对多)模型 日期:2012-05-05 |  来源:未知 |  作者:redice |  人围观 |  1 人鼓掌了! 鲲鹏Web数据抓取 - 专业Web ...

  4. Spring整合Hibernate图文步骤

    首先建立java Project工程 点击Finish完成 添加Hibernate和Spring所需要的jar包还有Mysql连接的jar包 创建Dao层,Dao层实现,Model层,Service层 ...

  5. 头文件为什么要加#ifndef #define #endif

    #ifndef 在头文件中的作用 在一个大的软件工程里面,可能会有多个文件同时包含一个头文件,当这些文件编译链接成一个可执行文件时 ,就会出现大量“重定义”的错误.在头文件中实用#ifndef #de ...

  6. C# 模拟鼠标写字

    经常看到别人拿个四四方方的写字板用笔写字,用C#其实也可以实现,大致思路就是处理鼠标的坐标和Graphics, 代码如下: 首先声明两个全局变量 bool isMouseDown = false; P ...

  7. Python基础学习笔记(九)常用数据类型转换函数

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-variable-types.html 3. http://www ...

  8. 2013 Multi-University Training Contest 10

    HDU-4698 Counting 题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax& ...

  9. MyEclipse + Tomcat 热部署问题

    myEclipse设置对应的tomcat时,只需要在jdk的Optional Java VM arguments中添加如下设置: -Xms256m -Xmx512m-Dcom.sun.manageme ...

  10. nodejs学习笔记<三>关于路由(url)

    在网站开发中,路由的设置非常关键.nodejs对路由处理封装了一个比较全面的模块. 来认识下url模块 1)在命令行(cmd)可以直接 node —> url 可直接查看url模块的所有方法. ...