mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(rs): add “1431. Kids With the Greatest Number of Candies”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
43d043b5e1
commit
d8009b9a4a
1 changed files with 41 additions and 0 deletions
41
problems/kids-with-the-greatest-number-of-candies.rs
Normal file
41
problems/kids-with-the-greatest-number-of-candies.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
struct Solution {}
|
||||||
|
impl Solution {
|
||||||
|
pub fn kids_with_candies(candies: Vec<i32>, extra_candies: i32) -> Vec<bool> {
|
||||||
|
let max = *candies.iter().max().unwrap();
|
||||||
|
candies
|
||||||
|
.iter()
|
||||||
|
.map(|candies| candies + extra_candies >= max)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example_1() {
|
||||||
|
assert_eq!(
|
||||||
|
Solution::kids_with_candies(vec![2, 3, 5, 1, 3], 3),
|
||||||
|
vec![true, true, true, false, true]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example_2() {
|
||||||
|
assert_eq!(
|
||||||
|
Solution::kids_with_candies(vec![4, 2, 1, 1, 2], 1),
|
||||||
|
vec![true, false, false, false, false]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example_3() {
|
||||||
|
assert_eq!(
|
||||||
|
Solution::kids_with_candies(vec![12, 1, 12], 10),
|
||||||
|
vec![true, false, true]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue