c++ Bucket


  • 0
    M

    class Solution {
    public:
    int distributeCandies(vector<int>& candies) {
    int kinds = 0, size = candies.size(), i = 0;
    int pos[100001] = {0};
    int neg[100001] = {0};
    for(int n = 0; n < size; n++){
    if(candies[n] < 0)
    neg[-candies[n]]++;
    else
    pos[candies[n]]++;
    }
    for(int n = 0; n < 100001; n++){
    if(neg[n] != 0)
    kinds++;
    if(pos[n] != 0)
    kinds++;
    }
    if(kinds >= (size/2))
    return size/2;
    return kinds;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.