Leetcode 分糖果

题目传送
在这里插入图片描述
水题,记忆化就ok

AC代码

class Solution {
    
    
public:
    int distributeCandies(vector<int>& candyType) {
    
    
            map<int,int> mp;
    int len = candyType.size();
    int m = 0;
    for(int i = 0;i < len;i++){
    
    
        if(mp[candyType[i]] == 0){
    
    
            m++;
            mp[candyType[i]] = 1;
        }
    }
    return min(len/2,m);
    }
};

猜你喜欢

转载自blog.csdn.net/moasad/article/details/121090371