Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #452

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
pull merged 3 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
May 22, 2024
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
Next Next commit
Update 0347.前K个高频元素.md
1. 修复了 JavaScript 解法二,堆 pop 方法无法处理数组长度 <= 1 的边界情况的问题
2. 删除了有误导性的条件判断。事实上,被删除的表达式永远为真(searchChild !== undefined)。原作者想表达的意思可能是 this.queue[searchChild] !== undefined,而实际上,这个判断也是不必要的,这种情况会被后续的 this.compare(index, searchChild) > 0 判断排除。但鉴于本项目的教程性质,直接去除可能会导致语义不清,考虑酌情将原处替换为 this.queue[searchChild] !== undefined 或直接删除
  • Loading branch information
xqsrpanz authored Apr 26, 2024
commit bcdf3e4ecdf352ee5f6a9d539bd980c66c3ea93e
2 changes: 1 addition & 1 deletion problems/0347.前K个高频元素.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class Heap {
let left = 1; // left 是左子节点下标 left + 1 则是右子节点下标
let searchChild = this.compare(left, left + 1) > 0 ? left + 1 : left;

while (searchChild !== undefined && this.compare(index, searchChild) > 0) { // 注意compare参数顺序
while (this.compare(index, searchChild) > 0) { // 注意compare参数顺序
[this.queue[index], this.queue[searchChild]] = [this.queue[searchChild], this.queue[index]];

// 更新下标
Expand Down

AltStyle によって変換されたページ (->オリジナル) /