题意:合并两个有序链表

/**
* 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. php的str_pad()函数

    实例 填充字符串的右侧,到30个字符的新长度 <?php $str = "Hello World"; echo str_pad($str,30,"."); ...

  2. python连接oracle数据库报错"DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "解决方案

    操作系统,python3.5, oracle_11, 均为64位:plsql 正常连接. 也顺利安装了cx_oracle 6.3,但是python进行连接的时候就会报错"DatabaseEr ...

  3. sqlmap 扫描注入漏洞

    .检测是否存在漏洞: sqlmap -u .获取数据库信息: sqlmap -u --dbs .数据库表信息: sqlmap -u -D security --tables .表中字段信息 sqlma ...

  4. 2、基本方法(Basic Recipes)

    学习目录:树莓派学习之路-GPIO Zero 官网地址:http://gpiozero.readthedocs.io/en/stable/recipes.html 环境:UbuntuMeta-16.0 ...

  5. PostgreSQL日期加减

    在PostgreSQL中可以直接对时间进行加减运算:. SELECT now()::timestamp + '1 year';  --当前时间加1年 SELECT now()::timestamp + ...

  6. 定时备份mysql数据库的shell脚本

    最近项目需要定时备份mysql数据库的数据,根据需求写了一份定时备份mysql数据库的脚本. -h mysql的地址  默认为localhost -P 端口号  默认为3306 -u 用户  默认为r ...

  7. js分享微信 ,微博 ,qq空间

    目前pc微信分享,是通过扫描二维码进行分享 var _title,_source,_sourceUrl,_pic,_showcount,_desc,_summary,_site, _width = , ...

  8. Vulnhub_DC7 记录

    基本步骤 经验 & 总结 对信息还是不敏感,其实也是因为对Drupal这个CMS并不熟悉,不知道哪些地方是默认的那些地方是作者修改,比如这个"DC7USER". 对Drup ...

  9. windows 删除进程

    win+R打开doc窗口 netstat -ano |findstr "8888" tskill 10120   结束进程

  10. 多进程 多进程queue

    多进程 import multiprocessing import threading import time def thread_run(): print(threading.get_ident( ...