Skip to content

Add solution 023[CPP] #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
modified solution of 023[CPP]
  • Loading branch information
KongJHong committed Oct 24, 2018
commit d021c98c0b50a5c22cf1c18559be0fe9d23250ba
15 changes: 15 additions & 0 deletions solution/023.Merge k Sorted Lists/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ class Solution {
#### CPP

```C++
class compare
{
public:
bool operator()(ListNode *l1,ListNode *l2){
//if(!l1 || !l2)
// return !l1;

if(l1 == NULL)return 1;
if(l2 == NULL)return 0;
return l1->val > l2->val;
//这里比较的是优先级,默认优先级排序是“<”号,若 l1Val > l2Val 返回真,即表示l1优先级比l2小,l2先入队
//队列的top()函数指的就是优先级最高的元素,即队头元素
}
};

class Solution{
public:
ListNode* mergeKLists(vector<ListNode*>& lists) {
Expand Down