Skip to content

Commit 2602edf

Browse files
Solved Network Delay Time (#137)
1 parent d88c5d2 commit 2602edf

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

C++/Network-delay-time.cpp.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Time complexity O(V+E)
2+
//Space Complexity O(V)
3+
class Solution {
4+
public:
5+
int networkDelayTime(vector<vector<int>>& times, int N, int K) {
6+
vector<long long int> d(N + 1, INT_MAX);
7+
d[K] = 0;
8+
for (int i = 0; i < N; ++i) {
9+
for (int j = 0; j < times.size(); ++j) {
10+
if (d[times[j][1]] > d[times[j][0]] + times[j][2]) {
11+
d[times[j][1]] = d[times[j][0]] + times[j][2];
12+
}
13+
}
14+
}
15+
16+
int a = *max_element(d.begin() + 1, d.end());
17+
return a >= INT_MAX ? -1 : a;
18+
}
19+
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
309309
| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [Java](./Java/NumberOfIslands.java) | O(R \* C) | O(R \* C) | Medium | BFS |
310310
| 127 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS |
311311
| 994 | [Rotten Oranges](https://leetcode.com/problems/rotting-oranges/) | [Python](./Python/994_Rotting_Oranges.py) | O(N \* M) | O(N \* M) | Medium | BFS |
312+
| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [C++](./C++/Network-delay-time.cpp) | _O(V+E))_ | O(V) | Medium | BFS |
313+
312314

313315
<br/>
314316
<div align="right">

0 commit comments

Comments
 (0)