static ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
        ListNode *temp = );
        ListNode *head = temp;
        if (l1 == NULL && l2 == NULL)
            return head;
        while (l1 != NULL && l2 != NULL) {
            if (l1->val <= l2->val) {
                temp->next = new ListNode(l1->val);
                temp = temp->next;
                l1 = l1->next;
            } else {
                temp->next = new ListNode(l2->val);
                temp = temp->next;
                l2 = l2->next;
            }
        }
        if (l1 == NULL && l2 != NULL)
            temp->next = l2;
        else if (l2 == NULL && l1 != NULL)
            temp->next = l1;
        return head->next;
    }

Leetcode--Merge Two Sorted Lists的更多相关文章

  1. [LeetCode] Merge k Sorted Lists 合并k个有序链表

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这 ...

  2. [LeetCode] Merge Two Sorted Lists 混合插入有序链表

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  3. LeetCode: Merge Two Sorted Lists 解题报告

    Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list shoul ...

  4. LeetCode: Merge k Sorted Lists 解题报告

    Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and descr ...

  5. [Leetcode] Merge k sorted lists 合并k个已排序的链表

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思 ...

  6. LeetCode:Merge k Sorted Lists

    题目链接 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexi ...

  7. LeetCode——Merge k Sorted Lists

    Discription: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its ...

  8. leetcode:Merge Two Sorted Lists(有序链表的归并)

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  9. leetcode -- Merge k Sorted Lists add code

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. [ ...

  10. LeetCode Merge k Sorted Lists (链表)

    题意 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity ...

随机推荐

  1. UITableView heightForHeaderInSection遇到的坑

    出现这种现象只需要把 heightforfoot改为0.01 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSectio ...

  2. Oracle学习笔记(1)----忘记用户名的密码该如何找回

    (1)在连接数据库之前需要打开如下服务: (2)如果忘记用户的密码 I:打开cmd窗口 II:键入命令:connect / as sysdba; III:alter user 用户名 identifi ...

  3. python实现排序算法

    冒泡排序  import randomdef BubbleSort(num):    n=len(num)    for i in range(0,n):        for j in range( ...

  4. JavaScript:this是什么?

    JavaScript:this是什么?定义:this是包含它的函数作为方法被调用时所属的对象.说明:这句话有点咬嘴,但一个多余的字也没有,定义非常准确,我们可以分3部分来理解它! 1.包含它的函数.2 ...

  5. python之RabbitMQ

    一.安装RabbitMQ 1. 安装erlang 1 2 3 4 tar xf otp_src_18.3.tar.gz cd otp_src_18.3 ./configure --prefix=/ma ...

  6. SQL的多表连接查询

    SQL的多表连接查询 多表连接查询具有两种规范,SQL92和SQL99规范. SQL92规范支持下列多表连接查询: (1)等值连接: (2)非等值连接: (3)外连接: (4)广义笛卡尔积: SQL9 ...

  7. Subtitute

    报表导出到Excel时,日期已经被格式化,有时候日期格式带星期几,比方说"2016-12-30 星期五",或者是"2016/12/30 星期五". 我不想要星期 ...

  8. ContentProvider跨进程共享数据

    借用ContentResolver类访问ContentProvider中共享的数据.通过getContentResolver()方法获得该类的实例. ContentResolver中的方法:inser ...

  9. NPOI导入xls,xlsx格式实例

    NPOI DLL下载地:http://npoi.codeplex.com/releases using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; us ...

  10. 话说C++中的左值、纯右值、将亡值

    写在前面 C++中有“左值”.“右值”的概念,C++11以后,又有了“左值”.“纯右值”.“将亡值”的概念.关于这些概念,许多资料上都有介绍,本文在拾人牙慧的基础上又加入了一些自己的一些理解,同时提出 ...