Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

题意:合并两个有序单链表,合并后的仍然是有序的。。。。。。。。。。。。。。。。。。。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {//首先判断有没有空链表的情况。。。。。if(l1 && !l2)return l1;if(!l1 && l2)return l2;if(!l1 && !l2)return NULL;//还是和之前的002题要保存新链表头,中间节点head负责遍历struct ListNode* head;struct ListNode* ret;//找到新链表的头if(l1->val<l2->val){head=l1;l1=l1->next;}else{head=l2;l2=l2->next;}ret=head;//负责遍历。哪个小就指向哪个,直到有一个遍历完while(l1&&l2){if(l1->val<l2->val){head->next=l1;l1=l1->next;}else{head->next=l2;l2=l2->next;}head=head->next;}//遍历完后看看谁还剩下直接指向剩下的部分if(l1){head->next=l1;}if(l2){head->next=l2;}return ret;}

。。。。。。。。。。。。。。。。太笨了。。。。。。。。。。。。。。。。继续练习吧少年。。。。。。。。。。。。。。。

转载于:https://blog.51cto.com/fulin0532/1864639

LeetCode021 Merge Two Sorted Listss C语言相关推荐

  1. LeetCode刷题记录15——21. Merge Two Sorted Lists(easy)

    LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) 目录 LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) ...

  2. LeetCode 之 JavaScript 解答第23题 —— 合并K个有序链表(Merge K Sorted Lists)

    Time:2019/4/10 Title: Merge K Sorted Lists Difficulty: Difficulty Author: 小鹿 题目:Merge K Sorted Lists ...

  3. Leetcode 21:Merge Two Sorted Lists(golang实现合并两条已经排序的链表)

    21.Merge Two Sorted Lists 题目链接:题目链接 Merge two sorted linked lists and return it as a new list. The n ...

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

  5. LeetCode 23. Merge k Sorted Lists--Python解法--优先队列,分治法

    题目地址:Merge k Sorted Lists - LeetCode Merge k sorted linked lists and return it as one sorted list. A ...

  6. LeetCode 21. Merge Two Sorted Lists--合并2个有序列表--python递归,迭代解法

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

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

  8. leetcode 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. 23 Merge k Sorted Lists

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

最新文章

  1. liunx导出mysql慢查询日志查看_查看 MySQL 慢查询日志文件-问答-阿里云开发者社区-阿里云...
  2. TheBeerHouse 网站项目学习笔记(5)---架构设计
  3. 一行代码求两个数的最大公约数
  4. 实用juniper SRX NAT小技巧。
  5. 可视化学习笔记 - ECharts
  6. 请求的站点不可用或无法找到怎么解决_被这六类WEB站攻击,打的生活不能自理?教你如何解决...
  7. SQLyog下载地址—Mysql的可视化(建议收藏)
  8. HTML表格(table)属性--左右(colspan)、上下(rowspan)合并、合并边框、位置 部分内容
  9. npm publish发布包时出现403错误no_perms Private mode enable, only admin can publish this module:
  10. springboot对接支付宝支付接口(详细开发步骤总结)
  11. 阿里云ECS安骑士离线修复步骤
  12. Ubuntu上,使用shell脚本实现鼠标自动点击,打开并设置桌面软件
  13. 前端面试总结之长沙五
  14. php版本大屏幕,PHP现场抽奖大屏幕互动系统
  15. 学会写作...【笔记】
  16. DDD战略建模在重构业务系统时的实践
  17. 一球成谜!咪咕直播联合即构打造世界杯直播答题新玩法
  18. 默纳克调试说明书_默纳克NICE调试说明书修改版
  19. 爬虫:python爬取简历模板
  20. 计算机网络(谢希仁-第八版)第五章习题全解

热门文章

  1. android 不同项目代码合并在一块,android - 是否可以将两个(正在积极开发中的)Android应用程序模块合并到同一个Android Studio项目中? - 堆栈内存溢出...
  2. oracle 游标内存自动释放,详解Oracle隐式游标和显式游标
  3. c语言数组指定位置插入和删除_玩转C语言链表,单链表/双向链表的建立/遍历/插入/删除...
  4. web测试和app测试相关
  5. 从另一页面调用html代码_GNE v0.1正式发布:4行代码开发新闻网站通用爬虫
  6. 两个for做数据插入_冒泡排序、选择排序、插入排序
  7. 无心剑随感《最完美的图形——圆》
  8. 在Chrome78浏览器上如何实现自动播放音视频
  9. Python案例:按键测试
  10. 2017.4.2 loli测试