Skip to content
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

[fix][javascript] advantage-shuffle #1581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
8 changes: 5 additions & 3 deletions 多语言解法代码/solution_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -7483,9 +7483,11 @@ class Solution {
var advantageCount = function(nums1, nums2) {
var n = nums1.length;
//给 nums2 降序排序
var maxpq = new PriorityQueue((pair1, pair2) => pair2[1] - pair1[1]);
var maxpq = new PriorityQueue({
compare: (pair1, pair2) => pair2[1] - pair1[1]
});
for (var i = 0; i < n; i++) {
maxpq.offer([i, nums2[i]]);
maxpq.enqueue([i, nums2[i]]);
}
//给 nums1 升序排序
nums1.sort((a, b) => a - b);
Expand All @@ -7494,7 +7496,7 @@ var advantageCount = function(nums1, nums2) {
var res = new Array(n);

while (!maxpq.isEmpty()) {
var pair = maxpq.poll();
var pair = maxpq.dequeue();
// maxval 是 nums2 中的最大值,i 是对应索引
var i = pair[0], maxval = pair[1];
if (maxval < nums1[right]) {
Expand Down