根据https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages-中不同语言支持的运行时,我使用https://github.com/datastructures-js/priority-queue#fromarray,因为这是一个受支持的库函数。
然而,当我使用
我遇到了一个错误。
然而,当我使用
const maxHeap = MaxPriorityQueue.fromArray(nums);
我遇到了一个错误。
Line 11 in solution.js
const maxHeap = MaxPriorityQueue.fromArray(nums);
^
TypeError: MaxPriorityQueue.fromArray is not a function
Line 11: Char 36 in solution.js (findKthLargest)
Line 34: Char 19 in solution.js (Object.<anonymous>)
Line 16: Char 8 in runner.js (Object.runner)
Line 23: Char 26 in solution.js (Object.<anonymous>)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
这符合提供的示例https://github.com/datastructures-js/priority-queue#js-3。
MaxPriorityQueue
对象吗? - Pointyconsole.log()
语句呢? - Pointy['_priority', '_heap']
。当然,在寻求帮助之前,我肯定已经尝试过console.log。 - Omkar Kulkarni