diff options
author | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /other/min_rounds_complete_all_tasks.rs | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip |
chore: move cpp and rust code to directory
Diffstat (limited to 'other/min_rounds_complete_all_tasks.rs')
-rw-r--r-- | other/min_rounds_complete_all_tasks.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/other/min_rounds_complete_all_tasks.rs b/other/min_rounds_complete_all_tasks.rs new file mode 100644 index 0000000..1c9b7dd --- /dev/null +++ b/other/min_rounds_complete_all_tasks.rs @@ -0,0 +1,30 @@ +use std::collections::HashMap; +struct Solution; + +impl Solution { + pub fn minimum_rounds(tasks: Vec<i32>) -> i32 { + let (mut map, mut ans) = (HashMap::new(), 0); + for t in tasks { + let val = map.get_mut(&t); + if let Some(v) = val { + *v += 1; + } else { + map.insert(t, 1); + } + } + for c in map.into_values() { + if c == 1 { + return -1; + } + ans += (c + 2) / 3; + } + ans + } +} + +fn main() { + let tasks1 = vec![2,2,3,3,2,4,4,4,4,4]; + let tasks2 = vec![2,3,3]; + println!("{}", Solution::minimum_rounds(tasks1)); + println!("{}", Solution::minimum_rounds(tasks2)); +} |