Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int distributeCandies(vector<int>& candies) {
- int max_candies = candies.size() / 2;
- //The length of the given array is in range [2, 10,000], and will be even.
- if (max_candies < 1 || max_candies > 5000 || candies.size() % 2) {
- return 0;
- }
- map<int,char> max_uniq;
- for(auto candy: candies) {
- //The number in given array is in range [-100,000, 100,000].
- if (candy < -100000 || candy > 100000) return 0;
- max_uniq[candy] = '1';
- }
- return ((int) max_uniq.size() < max_candies) ? max_uniq.size() : max_candies;
- }
- };
Add Comment
Please, Sign In to add comment