mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-07 18:30:20 +00:00
add solution for determining which kids can have the most candies
This commit is contained in:
1 parent
5fadd8b6e7
commit
ad9dad2f8b
3 files changed
+25
-9
No files matched your search
@@ -0,0 +1,25 @@
|
||||
class Solution {
|
||||
public:
|
||||
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
|
||||
int csize = candies.size();
|
||||
int i = 0;
|
||||
int current;
|
||||
int max = *std::max_element(candies.begin(), candies.end());
|
||||
|
||||
vector<bool> kids;
|
||||
|
||||
for (; i < csize; i++)
|
||||
{
|
||||
current = candies[i] + extraCandies;
|
||||
if (max <= current)
|
||||
{
|
||||
kids.push_back(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
kids.push_back(false);
|
||||
}
|
||||
}
|
||||
return kids;
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user