1514. Path with Maximum Probability | BFS | DFS | Leetcode POTD Explained

  Рет қаралды 76

Jeevesh Rai

Jeevesh Rai

Күн бұрын

Пікірлер: 1
@codeby_naruto
@codeby_naruto 18 күн бұрын
Code :- class Solution { public: double maxProbability(int n, vector& edges, vector& succProb, int start_node, int end_node) { vector adjList(n); for (int i = 0; i < edges.size(); i++) { int u = edges[i][0]; int v = edges[i][1]; adjList[u].push_back({ v, succProb[i] }); adjList[v].push_back({ u, succProb[i] }); } vector maxProb(n, 0); maxProb[start_node] = 1.0; priority_queue pq; pq.push({ 1.0, start_node }); while (!pq.empty()) { auto curr = pq.top(); pq.pop(); double currProb = curr.first; int currNode = curr.second; if(currNode==end_node) return maxProb[end_node]; for (auto node : adjList[currNode]) { int nextNode = node.first; double nextProb = node.second; if (currProb * nextProb > maxProb[nextNode]) { maxProb[nextNode] = currProb * nextProb; pq.push({ currProb * nextProb, nextNode }); } } } return maxProb[end_node]; } };
Valhalla - Where Are We? #JVMLS
51:07
Java
Рет қаралды 20 М.
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 37 МЛН
How Strong is Tin Foil? 💪
00:26
Preston
Рет қаралды 70 МЛН
725. Split Linked List in Parts | Leetcode POTD Explained
13:31
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 144 М.
Fast and Beautiful Assembly
34:28
Kay Lack
Рет қаралды 10 М.
How to Check if a User Exists Among Billions! - 4 MUST Know Strategies
12:44
Think Recursively, Execute Iteratively: Optimizing Dynamic Programming
19:52
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 37 МЛН