这个方法有点愚蠢
class Solution {
public:
int findLHS(vector<int>& nums) {
int len = 0;
if(nums.size() == 0) return len;
map<int,int>mp;
for(int i = 0;i<nums.size();i++)
{
if(!mp.count(nums[i]))
{
mp[nums[i]] = 1;
}
else mp[nums[i]]++;
}
for(auto it = mp.begin();it!=mp.end();it++)
{
if(mp.count(it->first+1))
{
cout<<it->first<<endl;
cout<<it->second<<endl;
len = max(len,it->second + mp[it->first+1]);
}
}
return len;
}
};