Skip to content

Commit ab2fb94

Browse files
committed
Replaced int[] with Pair
1 parent 97bcd93 commit ab2fb94

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/graph/network-delay-time.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ values={[
4545
```java
4646
// Network Delay Time
4747
// Dijkstra
48-
// Time Complexity: O(logN*E), Space Complexity: O(N + E)
48+
// Time Complexity: O(ElogN), Space Complexity: O(N + E)
4949
class Solution {
5050
public int networkDelayTime(int[][] times, int N, int K) {
5151
// adjacency list, map<vertex_id, map<vertex_id, weight>>
@@ -73,14 +73,14 @@ class Solution {
7373
Map<Integer, Integer> father = new HashMap<>();
7474

7575
// pair<distance, vertex_id>, min heap, sorted by distance from start to vertex_id
76-
Queue<int[]> pq = new PriorityQueue<>((a, b) -> (a[0] - b[0]));
76+
Queue<Pair<Integer, Integer>> pq = new PriorityQueue<>((a, b) -> a.getKey() - b.getKey());
7777

7878
// from start to start itself
79-
pq.offer(new int[]{0, start});
79+
pq.offer(new Pair(0, start));
8080
dist.put(start, 0);
8181

8282
while(!pq.isEmpty()){
83-
final int u = pq.poll()[1];
83+
final int u = pq.poll().getValue();
8484
if (!graph.containsKey(u)) continue; // leaf node
8585

8686
for(int v : graph.get(u).keySet()){
@@ -89,7 +89,7 @@ class Solution {
8989
final int shorter = dist.get(u)+ w;
9090
dist.put(v, shorter);
9191
father.put(v, u);
92-
pq.offer(new int[]{shorter, v});
92+
pq.offer(new Pair(shorter, v));
9393
}
9494
}
9595
}
@@ -108,3 +108,7 @@ class Solution {
108108

109109
</TabItem>
110110
</Tabs>
111+
112+
### 相关题目
113+
114+
- [Path with Maximum Probability](path-with-maximum-probability.md)

0 commit comments

Comments
 (0)