C++,先调用STL算法sort,然后计算最长连续
数组中的最长连续子序列
http://www.nowcoder.com/practice/eac1c953170243338f941959146ac4bf
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;
}