Skip to content

Commit e3e9437

Browse files
committed
Added Network Delay Time Structure
1 parent d854c5c commit e3e9437

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/network_delay_time.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// You are given a network of `n` nodes, labeled from `1` to `n`. You are also
2+
/// given `times`, a list of travel times as directed edges
3+
/// `times[i] = (ui, vi, wi)`, where `ui` is the source node, `vi` is the
4+
/// target node, and `wi` is the time it takes for a signal to travel from
5+
/// source to target.
6+
///
7+
/// We will send a signal from a given node `k`. Return the minimum time it
8+
/// takes for all the `n` nodes to receive the signal. If it is impossible for
9+
/// all the `n` nodes to receive the signal, return `-1`.
10+
struct Solution;
11+
12+
impl Solution {
13+
14+
// TODO: Implement
15+
pub fn network_delay_time(times: Vec<Vec<i32>>, n: i32, k: i32) -> i32 {
16+
0
17+
}
18+
19+
}
20+
21+
#[cfg(test)]
22+
mod tests {
23+
use super::Solution;
24+
25+
#[ignore]
26+
#[test]
27+
fn example_1() {
28+
let times = vec![vec![2,1,1], vec![2,3,1], vec![3,4,1]];
29+
let n = 4;
30+
let k = 2;
31+
let result = Solution::network_delay_time(times, n, k);
32+
assert_eq!(result, 2);
33+
}
34+
35+
#[ignore]
36+
#[test]
37+
fn example_2() {
38+
let times = vec![vec![1,2,1]];
39+
let n = 2;
40+
let k = 1;
41+
let result = Solution::network_delay_time(times, n, k);
42+
assert_eq!(result, 1);
43+
}
44+
45+
#[test]
46+
fn example_3() {
47+
let times = vec![vec![1,2,1]];
48+
let n = 2;
49+
let k = 2;
50+
let result = Solution::network_delay_time(times, n, k);
51+
assert_eq!(result, -1);
52+
}
53+
54+
}

0 commit comments

Comments
 (0)