力扣-594-最長和諧子序列-map 《count》

class Solution {
public:
    int findLHS(vector<int>& nums) {
        map<int,int> m;
        int ans=0;      
        for(auto c : nums)
        {
            m[c]++;
        }
        for(auto c : m)
        {
            if(m.count(c.first+1))//count...............
            {
                ans=max(ans,c.second+m[c.first+1]);
            }
        }
        return ans;
    }
};


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章