列表是升序的 # -*- coding: utf-8 -*- # 合并两个排序的数组 def merge_list(a, b): if not a: return b if not b: return a a_index = b_index = 0 ret = [] while a_index < len(a) and b_index < len(b): if a[a_index] <= b[b_index]: ret.append(a[a_index]) a_index += 1 el…
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. class Solution { public: ListNode *mergeKLists(vector<ListNode *> &lists) { int n = lists.size(); ) return nullptr; ) ]; ,n-); } ListNode* mergeKL…
Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 简单的链表去重而已啊,遍历一边就实现了: class Solution { public: ListNode* delet…
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. 题意:合并两个排好的链表并返回新的链表. 可以使用归并排序,从两链表的表头,取出结点,比较两值,将较小的放在新链表中.如1->3->5->6和2->4->7->8,先将1放入新链表,然后将3…