add: 230417
This commit is contained in:
parent
85fcd9e620
commit
036f3b7f5d
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include <iterator>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1431. Kids With the Greatest Number of Candies
|
||||||
|
*
|
||||||
|
* There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.
|
||||||
|
* Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.
|
||||||
|
* Note that multiple kids can have the greatest number of candies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static std::vector<bool> kidsWithCandies(const std::vector<int>&, int);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<bool> Solution::kidsWithCandies(const std::vector<int>& c, int ec) {
|
||||||
|
std::vector<bool> ret;
|
||||||
|
int max = *std::max_element(c.begin(), c.end());
|
||||||
|
std::transform(c.begin(), c.end(), std::back_inserter(ret), [&](int x) { return x + ec >= max; });
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
@ -4,4 +4,4 @@ PROJECT(2304)
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
SET(CMAKE_EXPORT_COMPILE_COMMANDS true)
|
SET(CMAKE_EXPORT_COMPILE_COMMANDS true)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2304 230414.cpp)
|
ADD_EXECUTABLE(2304 230417.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue