Skip to content

Commit 6094b52

Browse files
committed
Runtime: 254 ms (Top 50.50%) | Memory: 51.9 MB (Top 97.03%)
1 parent d09021a commit 6094b52

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/algorithms/S/Second Minimum Time to Reach Destination/Second Minimum Time to Reach Destination.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// Runtime: 254 ms (Top 50.50%) | Memory: 51.9 MB (Top 97.03%)
12
class Solution {
23
public int secondMinimum(int n, int[][] edges, int time, int change) {
34
Map<Integer, List<Integer>> g = new HashMap();
45
for(int[] e : edges) {
5-
int u = e[0], v = e[1];
6+
int u = e[0], v = e[1];
67
g.computeIfAbsent(u, x -> new ArrayList()).add(v);
78
g.computeIfAbsent(v, x -> new ArrayList()).add(u);
89
}
@@ -14,9 +15,9 @@ public int secondMinimum(int n, int[][] edges, int time, int change) {
1415
while(!q.isEmpty()) {
1516
int size = q.size();
1617
int[] cur = q.poll();
17-
int node = cur[0], t = cur[1]; // arriving time
18+
int node = cur[0], t = cur[1]; // arriving time
1819
if(dis[node] == t || uniqueVisit[node] >= 2) continue; // skip if it's same value or has been relaxed twice already
19-
uniqueVisit[node]++;
20+
uniqueVisit[node]++;
2021
dis[node] = t;
2122
if(node == n && uniqueVisit[node] == 2) return dis[node];
2223
// generate leaving time (waiting the green light)
@@ -27,4 +28,4 @@ public int secondMinimum(int n, int[][] edges, int time, int change) {
2728
}
2829
return -1;
2930
}
30-
}
31+
}

0 commit comments

Comments
 (0)