-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1514.py
21 lines (17 loc) · 822 Bytes
/
1514.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def maxProbability(self, n: int, edges: List[List[int]], succProb: List[float], start: int, end: int) -> float:
probability = [0] * n
probability[end] = 1
while True:
updated = False
for i, e in enumerate(edges):
first_node, second_node = e
if probability[first_node] < probability[second_node] * succProb[i]:
probability[first_node] = probability[second_node] * succProb[i]
updated = True
if probability[second_node] < probability[first_node] * succProb[i]:
probability[second_node] = probability[first_node] * succProb[i]
updated = True
if not updated:
break
return probability[start]