[Leetcode]-Merge Two Sorted Lists
2017-08-10 13:10
417 查看
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(NULL == l1) return l2; if(NULL == l2) return l1; struct ListNode* MergeList = NULL; if(l1->val < l2->val) { MergeList = l1; MergeList->next = mergeTwoLists(l1->next,l2); } else { MergeList = l2; MergeList->next = mergeTwoLists(l1,l2->next); } return MergeList; }
相关文章推荐
- leetcode 21. Merge Two Sorted Lists
- LeetCode ---Merge Two Sorted Lists
- Leetcode:Merge Two Sorted Lists
- Leetcode Problem.21—Merge Two Sorted Lists
- leetcode [Merge Two Sorted Lists]
- 【LeetCode】Merge Two Sorted Lists和Add TwoNumber解题报告
- leetcode Merge Two Sorted Lists
- [Leetcode] Merge Two Sorted Lists
- Merge Two Sorted Lists--LeetCode
- LeetCode - 21. Merge Two Sorted Lists
- [Leetcode]Merge Two Sorted Lists
- Leetcode 21 Merge Two Sorted Lists
- Leetcode: Merge Two Sorted Lists
- LeetCode 【21. Merge Two Sorted Lists】
- [LeetCode By Python] 21. Merge Two Sorted Lists
- LeetCode--Merge Two Sorted Lists
- 【Leetcode-Easy-21】Merge Two Sorted Lists
- [Leetcode] Merge two sorted lists
- leetcode 21. Merge Two Sorted Lists
- leetcode 【 Merge Two Sorted Lists 】 python 实现