楼主:
yam276 ('_')
2025-05-28 18:43:571431. Kids With the Greatest Number of Candies
https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
都简单题就多写一点
题意:
每个小孩有不同数量的糖果
你有一叠 e 颗糖果
要是每次把 e 颗糖果给一个小孩
能不能比原本拥有最多糖果的小孩多
Code:
impl Solution {
pub fn kids_with_candies(candies: Vec<i32>, extra_candies: i32)
-> Vec<bool>
{
let max_candies = candies.iter().max().unwrap();
candies
.iter()
.map(|&x| x + extra_candies >= *max_candies)
.collect()
}
}
一行链式解:
candies.iter()
.map(|&x| x + extra_candies >= *candies.iter().max().unwrap())
.collect()