Guest User

Untitled

a guest
Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int distributeCandies(vector<int>& candies) {
  4.  
  5. int max_candies = candies.size() / 2;
  6.  
  7. //The length of the given array is in range [2, 10,000], and will be even.
  8. if (max_candies < 1 || max_candies > 5000 || candies.size() % 2) {
  9. return 0;
  10. }
  11.  
  12. map<int,char> max_uniq;
  13. for(auto candy: candies) {
  14. //The number in given array is in range [-100,000, 100,000].
  15. if (candy < -100000 || candy > 100000) return 0;
  16. max_uniq[candy] = '1';
  17. }
  18.  
  19. return ((int) max_uniq.size() < max_candies) ? max_uniq.size() : max_candies;
  20. }
  21. };
Add Comment
Please, Sign In to add comment