1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-20 01:56:57 +02:00
LeetCode/rs/minimum-number-of-vertices-to-reach-all-nodes.rs
Matej Focko 2351dfd0ee
chore: unwrap one layer
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-12-12 14:36:00 +01:00

19 lines
579 B
Rust

impl Solution {
pub fn find_smallest_set_of_vertices(n: i32, edges: Vec<Vec<i32>>) -> Vec<i32> {
// It should be possible to use topological ordering + BFS, but…
let mut is_reachable: Vec<bool> = vec![false; n as usize];
for dst in edges.iter().map(|edge| edge[1] as usize) {
is_reachable[dst] = true;
}
let mut result: Vec<i32> = vec![];
for (i, &reachable) in is_reachable.iter().enumerate() {
if !reachable {
result.push(i as i32);
}
}
result
}
}