21. Merge Two Sorted Lists(Java)
2017-08-04 16:42
381 查看
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.
public 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(l2.next, l1); return l2; } } }
相关文章推荐
- Leetcode:21. Merge Two Sorted Lists(JAVA)
- 21. Merge Two Sorted Lists(java)
- 21. Merge Two Sorted Lists(合并有序链表)
- Merge Two Sorted Lists (Java)
- 21. Merge Two Sorted Lists(Linked List-Easy)
- leetcode:Merge Two Sorted Lists 【Java】
- [LeetCode][Java] Merge Two Sorted Lists
- 21. Merge Two Sorted Lists(Linked List)
- Merge Two Sorted Lists leetcode java
- [leetcode]21. Merge Two Sorted Lists(java)
- Merge Two Sorted Lists leetcode java
- 2.【排序】Merge Two Sorted Lists--Accepted Java code
- 21. Merge Two Sorted Lists(合并2个有序链表)
- 21. Merge Two Sorted Lists (Easy)
- Java [leetcode 21]Merge Two Sorted Lists
- (java)Merge Two Sorted Lists
- Merge Two Sorted Lists (Java)
- 21. Merge Two Sorted Lists
- java: Merge-two-sorted-lists
- (Java)LeetCode-21. Merge Two Sorted Lists