Skip to content

Commit 0a4c965

Browse files
committed
Runtime: 49 ms (Top 24.43%) | Memory: 65.2 MB (Top 52.71%)
1 parent 0c07368 commit 0a4c965

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 49 ms (Top 24.43%) | Memory: 65.2 MB (Top 52.71%)
12
class Solution {
23
HashMap<Integer, HashMap<Integer, Integer>> map = new HashMap<>();
34
public int networkDelayTime(int[][] times, int n, int k) {
@@ -8,20 +9,20 @@ public int networkDelayTime(int[][] times, int n, int k) {
89
map.get(times[i][0]).put(times[i][1], times[i][2]);
910
}
1011
int ans = BFS(k, n);
11-
12+
1213
return ans == 1000 ? -1 : ans;
1314
}
1415
public int BFS(int k, int n) {
1516
LinkedList<Integer> queue = new LinkedList<>();
16-
17+
1718
int[] timeReach = new int[n + 1];
1819
Arrays.fill(timeReach, 1000);
1920
timeReach[0] = 0;
20-
21+
2122
timeReach[k] = 0;
22-
23+
2324
queue.add(k);
24-
25+
2526
while (!queue.isEmpty()) {
2627
int rv = queue.remove();
2728
for (int nbrs : map.get(rv).keySet()) {
@@ -32,13 +33,13 @@ public int BFS(int k, int n) {
3233
}
3334
}
3435
}
35-
36+
3637
int time = 0;
37-
38+
3839
for (int i : timeReach) {
3940
time = Math.max(i, time);
4041
}
41-
42+
4243
return time;
4344
}
44-
}
45+
}

0 commit comments

Comments
 (0)