标签:while index amp div class -- highlight public solution
class Solution { public: ListNode* mergeKLists(vector<ListNode*>& lists) { ListNode* head = NULL; ListNode* current = NULL; for (int i = 0; i < lists.size(); ++i){ if (!lists[i]){ lists.erase(lists.begin()+i); --i; } } while (lists.size()){ int min_value=lists[0]->val; int min_index = 0; for (int i = 1; i < lists.size(); ++i){ if (lists[i]->val < min_value){ min_index = i; min_value = lists[i]->val; } } if (head == NULL){ head = lists[min_index]; current = head; } else { current->next = lists[min_index]; current = current->next; } lists[min_index] = lists[min_index]->next; if (!lists[min_index]){ lists.erase(lists.begin()+min_index); } } return head; } };
leetcode problem :23. Merge k Sorted Lists
标签:while index amp div class -- highlight public solution
原文地址:http://www.cnblogs.com/nosaferyao/p/7906255.html