题意:合并两个有序链表

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
if(l1 == NULL) return l2;
if(l2 == NULL) return l1;
if(l1 -> val <= l2 -> val){
l1 -> next = mergeTwoLists(l1 -> next, l2);
return l1;
}
else{
l2 -> next = mergeTwoLists(l1, l2 -> next);
return l2;
}
}
};

  

LeetCode 21. Merge Two Sorted Lists(合并两个有序链表)的更多相关文章

  1. leetcode 21 Merge Two Sorted Lists 合并两个有序链表

    描述: 合并两个有序链表. 解决: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if (!l1) return l2; if (!l2) ...

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

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

  3. [LeetCode]21. 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. 【LeetCode】21. Merge Two Sorted Lists 合并两个有序链表

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:合并,有序链表,递归,迭代,题解,leetcode, 力 ...

  5. 【LeetCode】Merge Two Sorted Lists(合并两个有序链表)

    这道题是LeetCode里的第21道题. 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1-&g ...

  6. 21. Merge Two Sorted Lists(合并2个有序链表)

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

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

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

  8. [leetcode]21. 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. 021 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 ...

  10. [LeetCode] 21. 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 ...

随机推荐

  1. 【REST详述及RESTful规范】

    目录 Web服务交互 理解REST 什么是资源? 什么是URI.URL? 统一资源接口 资源的表述 状态转移 小结 "RESTful是一种软件的架构风格.设计风格,为客户端和服务端的交互提供 ...

  2. Wx-小程序-长按复制文本

    view: <text bindlongtap='copy' data-name='{{name}}'>{{item.name}}</text> js: copy(e) { v ...

  3. 吴裕雄 python 神经网络——TensorFlow 完整神经网络样例程序

    import tensorflow as tf from numpy.random import RandomState batch_size = 8 w1= tf.Variable(tf.rando ...

  4. 异常的jvm(java虚拟机)与异常处理try catch与throwable

  5. 什么是DO / DTO / BO / VO /AO ?

    转载:https://blog.csdn.net/ouzhuangzhuang/article/details/86644476 POJO 是 DO / DTO / BO / VO 的统称. DO(D ...

  6. RTT学习之启动流程

    总结RT-Thread的启动流程. 非运行时与运行时的image文件分别是什么样的,请画下来.是谁将 RW 段中的  RW-data(初始化的全局变量)搬运到 RAM 中? MDK环境下各种数据段存储 ...

  7. 【PAT甲级】1088 Rational Arithmetic (20 分)

    题意: 输入两个分数(分子分母各为一个整数中间用'/'分隔),输出它们的四则运算表达式.小数需要用"("和")"括起来,分母为0的话输出"Inf&qu ...

  8. jquery Ajax标准规范写法

    $.ajax({ url:"http://www.xxx",//请求的url地址 dataType:"json",//返回的格式为json async:true ...

  9. VS中消除ANSI API警告

    最近在VS上写网络程序遇到许多问题,因为VS中将许多ANSI中的API都重写了,那些API大多有漏洞或不能支持现在的一些编程需求了,所以在VS中使用会因为警告而不能用. 但一些老API用着比较方便,了 ...

  10. ASCII码排序 题解

    1. while(scanf("%c%c%c%*c",&a,&b,&c)!=EOF) 这里需要注意  输入多组语句 while后面不能加分号: 2.%*c& ...