【LeetCode】C# 21、Merge Two Sorted Lists
来源:互联网 发布:sql 设置列默认值 编辑:程序博客网 时间:2024/06/06 17:54
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.
合并两个有序的链表成一个有序链表。
思路:只有一个过程,就是判断两个链表当前的值,把小的给结果ListNode,然后进入下一个循环,就能实现整合列表。
/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int x) { val = x; } * } */public class Solution { public ListNode MergeTwoLists(ListNode l1, ListNode l2) { if(l1 == null) return l2; if(l2 == null) return l1; ListNode head = (l1.val < l2.val) ? l1 : l2; ListNode nonhead = (l1.val < l2.val) ? l2:l1; head.next = MergeTwoLists(head.next,nonhead); return head; }}
阅读全文
0 0
- 【LeetCode】C# 21、Merge Two Sorted Lists
- LeetCode #21 Merge Two Sorted Lists C# Solution
- LeetCode(21)Merge Two Sorted Lists
- [LeetCode 21] Merge Two Sorted Lists Solution
- [leetcode 21] Merge Two Sorted Lists
- LeetCode 21:Merge Two Sorted Lists
- LeetCode | #21 Merge Two Sorted Lists
- [Leetcode] 21 - Merge Two Sorted Lists
- leetcode.21------------Merge Two Sorted Lists
- [leetcode]21 Merge Two Sorted Lists
- Leetcode NO.21 Merge Two Sorted Lists
- leetcode[21 链表]Merge Two Sorted Lists
- leetcode-21 Merge Two Sorted Lists
- leetCode #21 Merge Two Sorted Lists
- leetcode 21 Merge Two Sorted Lists
- [Leetcode 21, Easy] Merge Two Sorted Lists
- LeetCode 21 Merge Two Sorted Lists
- Leetcode 21 Merge Two Sorted Lists
- ubuntu主机初始化
- Construct制作中玩家不能移动?
- #长连接#WebSocket\长连接\轮询
- 从传统工控软件角度对百度天工平台解读
- theano 安装解决方案
- 【LeetCode】C# 21、Merge Two Sorted Lists
- 1047. 编程团体赛(20)
- 虚幻4调试模式和关于虚幻引擎4.18和4.19源码版,无法使用DebuggameEditor调试模式的解决方法。
- Lintcode-贪心-最大子数组和最小子数组
- SprintBoot学习笔记(4):登录(Hibernate+Mysql)
- JVM内幕:Java虚拟机详解
- 如何看待那些不能重现的bug
- [BZOJ]1923: [Sdoi2010]外星千足虫 高斯消元解xor方程组
- bzoj 1222: [HNOI2001]产品加工