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

Method maxProbability

java/1514-path-with-maximum-probability.java:2–25  ·  view source on GitHub ↗
(int n, int[][] edges, double[] succProb, int start, int end)

Source from the content-addressed store, hash-verified

1class Solution {
2 public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) {
3 // create the graph
4 List<double[]>[] graph = new LinkedList[n];
5 for (int i = 0; i < n; i++) {
6 graph[i] = new LinkedList<>();
7 }
8
9 for (int i = 0; i < edges.length; i++) {
10 double from = edges[i][0];
11 double to = edges[i][1];
12 double weight = succProb[i];
13 double[] m = new double[2];
14 m[0] = to;
15 m[1] = weight;
16 graph[edges[i][0]].add(m);
17 double[] k = new double[2];
18 k[0] = from;
19 k[1] = weight;
20 graph[edges[i][1]].add(k);
21 }
22
23 // call dijkstra and return
24 return dijkstra(start, end, graph);
25 }
26
27 class State{
28 int id;

Callers

nothing calls this directly

Calls 2

dijkstraMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected