题解 | #数组中的最长连续子序列#
数组中的最长连续子序列
https://www.nowcoder.com/practice/eac1c953170243338f941959146ac4bf
class Solution { public: int MLS(vector<int>& arr) { // write code here if(arr.empty()) return 0; int longest=1; int count=1; sort(arr.begin(),arr.end()); for(int i=1;i<arr.size();++i){ if(arr.at(i)==arr.at(i-1)) continue; if(arr.at(i)-arr.at(i-1)==1) ++count; else count=1; longest=max(longest,count); } return longest; } };