sort如果自己写cmp在LeetCode里要将其定义为static
如果要写优先队列则需要:
class Solution {
public:
struct Cmp {
bool operator()(ListNode* a, ListNode* b) {
return a->val > b->val;
}
};
ListNode* mergeKLists(vector<ListNode*>& lists) {
priority_queue<ListNode*, vector<ListNode*>, Cmp> p;
}
};