Skip to content

Commit a55b5df

Browse files
authored
Create kids-with-the-greatest-number-of-candies.cpp
1 parent bc67cfe commit a55b5df

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
7+
const auto& max_num = *max_element(cbegin(candies), cend(candies));
8+
vector<bool> result;
9+
transform(cbegin(candies), cend(candies), back_inserter(result),
10+
[&extraCandies, &max_num](const auto& x) {
11+
return x + extraCandies >= max_num;
12+
});
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)