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
Generated
-1
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CMakePythonSetting">
|
<component name="CMakePythonSetting">
|
||||||
<option name="pythonIntegrationState" value="YES" />
|
<option name="pythonIntegrationState" value="YES" />
|
||||||
|
|||||||
Generated
-8
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user