Skip to content

Commit 97ccd9f

Browse files
authored
Create distribute-candies.cpp
1 parent 5f08cf7 commit 97ccd9f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

C++/distribute-candies.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
int distributeCandies(vector<int>& candies) {
7+
unordered_set<int> lookup;
8+
for (const auto& candy: candies) {
9+
lookup.emplace(candy);
10+
}
11+
return min(lookup.size(), candies.size() / 2);
12+
}
13+
};

0 commit comments

Comments
 (0)