Skip to content

Commit

Permalink
Create distribute-candies.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jun 6, 2017
1 parent 5f08cf7 commit 97ccd9f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions C++/distribute-candies.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Time: O(n)
// Space: O(n)

class Solution {
public:
int distributeCandies(vector<int>& candies) {
unordered_set<int> lookup;
for (const auto& candy: candies) {
lookup.emplace(candy);
}
return min(lookup.size(), candies.size() / 2);
}
};

0 comments on commit 97ccd9f

Please sign in to comment.