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. 常用oracle表空间查询语句

    --查询数据库表空间使用情况 select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/ ...

  2. EF 数据初始化

    数据库不存在时重新创建数据库: Database.SetInitializer<testContext>(new DropCreateDatabaseAlways<testConte ...

  3. jQuery属性操作

    jQuery 的属性操作的核心部分其实就是对底层 getAttribute().setAttributes()等方法的一系列兼容性处理 ...if ( notxml ) { name = name.t ...

  4. greenDAO3 基本使用

    greenDAO3基本使用 greenDAO3开始使用注解的方式定义实体类(entity),并且是通过安装gradle插件来生成代码.之前的版本则是通过建立一个独立的Java-lib工程来存放生成的文 ...

  5. mysql基本语句

    mysql -u root -p; 登录数据库 show databases; 展示数据库 show tables; 展示表 desc messages; 查看messages表的结构 drop da ...

  6. angular学习之关于ng-class详解

    1,定义和用法 ng-class 指令用于给 HTML 元素动态绑定一个或多个 CSS 类. ng-class 指令的值可以是字符串,对象,或一个数组. 如果是字符串,多个类名使用空格分隔. 如果是对 ...

  7. IDEA UTF-8 中含 bom 运行报错 批量处理将bom移除

    将eclipse中的项目导入到idea或者as的环境中,遇到UTF-8含有BOM编码报错的问题,之前每次遇到这样的问题都特么用EditPlus一个一个的转换,感觉太烦了,后面就自己写了一个批量处理的工 ...

  8. Swift 语法

    三目运算        let p=10         let x:Int? =  12         let  m:Optional = 11         print(x!+p+m!)   ...

  9. div+css 设计下拉

    css样式 <style type="text/css"> <!-- /* www.divcss5.com CSS下拉菜单实例 */ * { margin:; p ...

  10. 今天学的是 HTML基本元素、基本语法元素特点等,就发图片吧。

    现在我们新手用的软件是:Adobe Dreamweaver CS6 按照下面格式来改,以后点HTML5直接就改过来了. 可以敲敲这些代码,大家一起学习. <!doctype html>&l ...