题意:链表排序
code:(nLogn)
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
class Solution {
priority_queue<int,vector<int>,greater<int> > q;
public:
ListNode *sortList(ListNode *head) {
ListNode *tmp = head;
while(tmp){
q.push(tmp->val);
tmp = tmp->next;
}
tmp = head;
while(tmp){
tmp->val = q.top();
q.pop();
tmp = tmp->next;
}
return head;
}
};