class Solution { public: int findLHS(vector<int>& nums) { int res=0; map<int,int> m; for(auto num:nums) ++m[num]; for(auto a:m){ if (m.count(a.first+1)){ res=max(res,m[a.first]+m[a.first+1]); } } return res; } };
原文地址:https://www.cnblogs.com/learning-c/p/9735430.html
时间: 2024-10-10 16:00:20