add solution for determining which kids can have the most candies

This commit is contained in:
bobbert committed 2026-05-06 18:40:14 +01:00
1 parent 5fadd8b6e7
commit ad9dad2f8b
3 files changed
+25 -9

No files matched your search

-1
View File
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Leet-Code-prog.iml" filepath="$PROJECT_DIR$/.idea/Leet-Code-prog.iml" />
</modules>
</component>
</project>
@@ -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;
}
};