Created
November 10, 2018 03:15
-
-
Save zhangxiaomu01/e996a57a251dcbaa70b4a62590b5ba8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: | |
ListNode* mergeKLists(vector<ListNode*>& lists) { | |
vector<int> myVector; | |
int len_l = lists.size(); | |
for(int i = 0; i < len_l; i++){ | |
ListNode* temp = lists[i]; | |
while(temp){ | |
myVector.push_back(temp->val); | |
temp = temp->next; | |
} | |
} | |
sort(myVector.begin(), myVector.end()); | |
ListNode* head = new ListNode(0); | |
ListNode* p_NewList = head; | |
len_l = myVector.size(); | |
for(int i = 0; i < len_l; i++){ | |
ListNode* temp = new ListNode(myVector[i]); | |
p_NewList->next = temp; | |
p_NewList = p_NewList->next; | |
} | |
return head->next; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment