排序再比较
public class Solution {
/**
* max increasing subsequence
* @param arr int整型一维数组 the array
* @return int整型
*/
public int MLS (int[] arr) {
// write code here
int len = arr.length;
if (len == 0 || arr == null){
return 0;
}
Arrays.sort(arr);
int count = 1;
int res = 1;
for (int i = 1; i < len; i++) {
if (arr[i] == arr[i-1]){
continue;
}else if (arr[i] == arr[i-1]+1){
count++;
}else {
count = 1;
}
res = Math.max(res,count);
}
return res;
}
}