Skip to content

Commit d021c98

Browse files
committed
modified solution of 023[CPP]
1 parent 9b0d38e commit d021c98

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

solution/023.Merge k Sorted Lists/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ class Solution {
8383
#### CPP
8484

8585
```C++
86+
class compare
87+
{
88+
public:
89+
bool operator()(ListNode *l1,ListNode *l2){
90+
//if(!l1 || !l2)
91+
// return !l1;
92+
93+
if(l1 == NULL)return 1;
94+
if(l2 == NULL)return 0;
95+
return l1->val > l2->val;
96+
//这里比较的是优先级,默认优先级排序是“<”号,若 l1Val > l2Val 返回真,即表示l1优先级比l2小,l2先入队
97+
//队列的top()函数指的就是优先级最高的元素,即队头元素
98+
}
99+
};
100+
86101
class Solution{
87102
public:
88103
ListNode* mergeKLists(vector<ListNode*>& lists) {

0 commit comments

Comments
 (0)