class Solution {
public:
   ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
   ListNode *p;

ListNode *p1=p; 
  while(l1!=NULL && l2!=NULL){
      if((l1->val)<(l2->val)){
           p->next=l1;
           p=p->next;
           l1=l1->next;
  }
else{
  p->next=l2;
  p=p->next;
  l2=l2->next;
  }
}

if(!l1) p->next=l2;
     if(l2==NULL) p->next=l1;
     return p1->next;
}
};

两个升序链表的合并 Merge Two Sorted Lists 【 leetcode】的更多相关文章

  1. Merge Two Sorted Lists - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Merge Two Sorted Lists - LeetCode 注意点 两个链表长度可能不一致 解法 解法一:先比较两个链表长度一致的部分,多余的部分 ...

  2. 23. Merge k Sorted Lists - LeetCode

    Question 23. Merge k Sorted Lists Solution 题目大意:合并链表数组(每个链表中的元素是有序的),要求合并后的链表也是有序的 思路:遍历链表数组,每次取最小节点 ...

  3. 链表经典题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 ...

  4. Merge Two Sorted Lists—LeetCode

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

  5. Merge k Sorted Lists Leetcode Java

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

  6. Merge Two Sorted Lists leetcode java

    题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  7. Merge k Sorted Lists [LeetCode]

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

  8. 蜗牛慢慢爬 LeetCode 23. Merge k Sorted Lists [Difficulty: Hard]

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

  9. LeetCode 21. 合并两个有序链表(Merge Two Sorted Lists)

    21. 合并两个有序链表 21. Merge Two Sorted Lists 题目描述 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. LeetCode ...

随机推荐

  1. 高性能Linux服务器 第10章 基于Linux服务器的性能分析与优化

    高性能Linux服务器 第10章    基于Linux服务器的性能分析与优化 作为一名Linux系统管理员,最主要的工作是优化系统配置,使应用在系统上以最优的状态运行.但硬件问题.软件问题.网络环境等 ...

  2. Flask 与 Celery 在 windows 下的集成问题

    Flask 与 Celery 在 windows 下的集成问题 所有的 Web 框架内部的视图中不适合执行需要长时间运行的任务,包括 Flask .Django 等.这类型的任务会阻塞 Web 的响应 ...

  3. Redhat linux 挂载命令mount

    命令格式: mount [-t vfstype] [-o options] device dir 其中: 1.-t vfstype 指定文件系统的类型,通常不必指定.mount 会自动选择正确的类型. ...

  4. python判断key是否在字典用in不用has_key

    小测试 in del.py import datetime cur = datetime.datetime.now() num = 1 a_list = {"a":1, " ...

  5. Python_01 在DOS环境运行python程序

    >怎么在DOS环境运行一个python程序 >>在文本编辑器中编辑程序,最后保存成   文件名.py  的格式 >>在DOS界面下找到源程序所在的路径,然后用  pyth ...

  6. zookeeper分布式环境的搭建

    官网配置地址:http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html 安装jdk 关闭防火墙 下载zookeeper-3.3.6并解压 ...

  7. sql语句查询出数据重复,取唯一数据

    select distinct mr.id,ifnull(mr.pid,0) as pid,mr.name from sys_role_res srr left join main_res mr on ...

  8. Oracle Hang Manager

    名词术语1.Cross Boundary Hang 交叉边界hang.在12.1.0.1中,hang manager可以检测database和asm之间的hang.2.Deadlock or Clos ...

  9. 异步调用webservice

    一.异步调用 asynchronous call(异步调用):一个可以无需等待被调用函数的返回值就让操作继续进行的方法 举例: 异步调用就是你 喊 你朋友吃饭 ,你朋友说知道了 ,待会忙完去找你 ,你 ...

  10. Fixed 鸟粪一样的TreeView下的NodeMouseDoubleClick Bug

    private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { Rectangl ...