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. preg_match_all

    <meta charset="utf8"> <?php set_time_limit (0); for($i=1;$i<34;$i++){ $url = & ...

  2. [转载]快速搭建Spring MVC 4开发环境

    (一)工作环境准备: JDK 1.7 Eclipse Kepler Apache Tomcat 8.0 (二)在Eclipse中新建Maven工程,在Archetype类型中,选择“maven-arc ...

  3. Could not find class XXX referenced from method XXX.<YYY>

    Since some ADT-Version you have to set which libraries / projects should be exported too. Project-Pr ...

  4. activity传值到fragment

    1,初始化fragment时候: @Override public void onAttach(Activity activity) { /** 注册广播 */  initBroadcast(); s ...

  5. string函数分析

    string函数分析string函数包含在string.c文件中,经常被C文件使用.1. strcpy函数原型: char* strcpy(char* str1,char* str2);函数功能: 把 ...

  6. CAD出图

    今天帮着客户输出图纸,用打印命令,设置打印参数,选择dwg到pdf打印机.设置图纸大小等参数 CAD满图纸输出 按照比例尺输出 plot,一般图纸绘制是已经有一个比例尺,所以按照1:1输出,如果图纸是 ...

  7. [转][C++ 11]override and final - write clean and maintainable C++ code

    原文: http://arne-mertz.de/2015/12/modern-c-features-override-and-final/ Today I write about a pair of ...

  8. Git 使用的想法

    git rebase 每个提交(commit)取消掉,并且把它们临时 保存为补丁(patch)(这些补丁放到".git/rebase"目录中),然后 git fetch origi ...

  9. MQ基础

    1. 什么时候用activeMQ 在大量场合,ActiveMQ和异步消息对系统架构有意味深长的影响.下面举一些例子: 1). 异构系统集成 2). 取代RPC 3). 应用间的解耦 4). 事件驱动架 ...

  10. Android Bundle类

    根据google官方的文档(http://developer.android.com/reference/android/os/Bundle.html) Bundle类是一个key-value对,“A ...