1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

chore: add the rest of the local code

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-06-03 22:39:34 +02:00
parent e0f7ae0937
commit 988f8fb927
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet, VecDeque};
struct Solution {}
impl Solution {
fn from_managers(managers: &[i32]) -> HashMap<usize, HashSet<usize>> {
let mut mapping = HashMap::new();
@ -35,3 +36,43 @@ impl Solution {
minutes
}
}
fn main() {}
#[cfg(test)]
mod tests {
use super::*;
// Input: n = 1, headID = 0, manager = [-1], informTime = [0]
// Output: 0
// Explanation: The head of the company is the only employee in the company.
#[test]
fn example_1() {
assert_eq!(Solution::num_of_minutes(1, 0, vec![-1], vec![0]), 0);
}
// Input: n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]
// Output: 1
// Explanation: The head of the company with id = 2 is the direct manager of all the employees in the company and needs 1 minute to inform them all.
// The tree structure of the employees in the company is shown.
#[test]
fn example_2() {
assert_eq!(
Solution::num_of_minutes(6, 2, vec![2, 2, -1, 2, 2, 2], vec![0, 0, 1, 0, 0, 0]),
1
);
}
#[test]
fn regression_1() {
assert_eq!(
Solution::num_of_minutes(
15,
0,
vec![-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],
vec![1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
),
3
);
}
}