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

Function search

javascript/0787-cheapest-flights-within-k-stops.js:36–52  ·  view source on GitHub ↗
(graph, src, dst, seen, minHeap)

Source from the content-addressed store, hash-verified

34};
35
36const search = (graph, src, dst, seen, minHeap) => {
37 while (!minHeap.isEmpty()) {
38 const [cost, city, stops] = minHeap.dequeue().element;
39
40 seen.set(city, stops);
41
42 const isTarget = city === dst;
43 if (isTarget) return cost;
44
45 const canSkip = stops <= 0;
46 if (canSkip) continue;
47
48 checkNeighbors(graph, cost, city, stops, seen, minHeap);
49 }
50
51 return -1;
52};
53
54var checkNeighbors = (graph, cost, city, stops, seen, minHeap) => {
55 for (let [nextCity, nextCost] of graph[city]) {

Callers 1

findCheapestPriceFunction · 0.70

Calls 3

checkNeighborsFunction · 0.70
isEmptyMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected