Title: #743 - Network Delay Time - LeetCode JavaScript Solutions
Open Graph Title: #743 - Network Delay Time - LeetCode JavaScript Solutions
X Title: #743 - Network Delay Time - LeetCode JavaScript Solutions
Description: You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, ...
Open Graph Description: You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, ...
X Description: You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/network-delay-time
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/network-delay-time","name":"#743 - Network Delay Time - LeetCode JavaScript Solutions","description":"You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[][]} times\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar networkDelayTime = function(times, n, k) {\n const time = new Array(n + 1).fill(Infinity);\n\n time[k] = 0;\n\n for (let i = 0; i < n; i++) {\n for (const [u, v, w] of times) {\n if (time[u] === Infinity) continue;\n if (time[v] > time[u] + w) {\n time[v] = time[u] + w;\n }\n }\n }\n\n let result = 0;\n for (let i = 1; i <= n; i++) {\n result = Math.max(result, time[i]);\n }\n\n return result === Infinity ? -1 : result;\n};","keywords":"LeetCode 743, #743 - Network Delay Time, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/network-delay-time |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/network-delay-time/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0743-network-delay-time.js |
| Depth-First Search | https://leetcodejavascript.com/tags/depth-first-search |
| Breadth-First Search | https://leetcodejavascript.com/tags/breadth-first-search |
| Heap Priority Queue | https://leetcodejavascript.com/tags/heap-priority-queue |
| Graph | https://leetcodejavascript.com/tags/graph |
| Shortest Path | https://leetcodejavascript.com/tags/shortest-path |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow