MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / buildGraph

Function buildGraph

javascript/0787-cheapest-flights-within-k-stops.js:21–34  ·  view source on GitHub ↗
(n, flights, src, dst, K)

Source from the content-addressed store, hash-verified

19});
20
21var buildGraph = (n, flights, src, dst, K) => {
22 const { graph, seen, minHeap } = initGraph(n);
23
24 for (const [src, dst, cost] of flights) {
25 graph[src].push([dst, cost]);
26 }
27
28 const priority = 0;
29 const node = [priority, src, K + 1];
30
31 minHeap.enqueue(node, priority);
32
33 return { graph, seen, minHeap };
34};
35
36const search = (graph, src, dst, seen, minHeap) => {
37 while (!minHeap.isEmpty()) {

Callers 1

findCheapestPriceFunction · 0.70

Calls 2

initGraphFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected