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 together the nodes of the first two lists.
solution:
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 together the nodes of the first two lists.
solution:
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;
}
}
};
第一次公共關係課上,老師給同學們拿出一個蘋果說,這個蘋果是早上在家門口的市場上買來的,大約0.5元錢,如果不考慮客觀條件,給大家5分鐘的時間,依
<script language='javascript' src='http://www.taizhou.la/AD/ad.js'></script