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. AES对称加密算法原理

    原著:James McCaffrey 翻译:小刀人 原文出处:MSDN Magazine November 2003 (Encrypt It) 本文的代码下载:msdnmag200311AES.exe ...

  2. Android RecycleView + CardView 控件简析

    今天使用了V7包加入的RecycleView 和 CardView,写篇简析. 先上效果图: 原理图: 这是RecycleView的工作原理: 1.LayoutManager用来处理RecycleVi ...

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

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

  4. iOS block在两个页面间的简单传值

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  5. openId 列表

    http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html 根据OpenID列表群发[订阅号不可用,服务号认证后可用] ...

  6. Windows2000安装Winform Clickonce提示升级系统版本的解决方案

    Windows2000安装Winform Clickonce提示升级系统版本.只需要把所有应用的DLL的独立性设置为false就可以了.

  7. Java基础之一组有用的类——Observable和Observer对象(Horrific)

    控制台程序. Obserable类提供了一个有趣的机制,可以把类对象中发生的改变通知给许多其他类对象. 对于可以观察的对象来说,类定义中需要使用java.util.Observable类.只需要简单地 ...

  8. mongodb概念

    一.mongodb与关系型数据库的一些概念上的改变 sql术语 mongodb术语 说明 database database 数据库 table collection 表/集合 row documen ...

  9. Climbing Stairs - Print Path

    stair climbing, print out all of possible solutions of the methods to climb a stars, you are allowed ...

  10. 树链剖分(单点更新,求区间最值,区间求和Bzoj1036)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 5759  Solved: 2383 [Submi ...