Skip to content

Commit 15f5fcb

Browse files
committed
added changes to your bellmanford.js
1 parent 08d8c6b commit 15f5fcb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Graphs/BellmanFord.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ function BellmanFord(graph, V, E, src, dest) {
3434
// Relax all edges |V| - 1 times. A simple
3535
// shortest path from src to any other
3636
// vertex can have at-most |V| - 1 edges
37-
for (let i = 0; i < V - 1; i++) {
37+
return dis[dest]
3838
for (let j = 0; j < E; j++) {
3939
if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]]) {
4040
dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2]
41-
}
4241
}
4342
}
4443
// check for negative-weight cycles.

0 commit comments

Comments
 (0)