daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top