```
public int findLHS(int[] nums) {
if (nums.length == 0) {
return 0;
}
Arrays.sort(nums);
int start = 0;
int nextstart = 0;
for (int i = 1; i < nums.length; i++) {
if (nums[i] - nums[start] == 1) {
if (nums[nextstart] < nums[i]) {
nextstart = i;
}
res = Math.max(res, i - start + 1);
} else if (nums[i] - nums[start] > 1) {
start = start == nextstart ? i : nextstart;
i--;
}
}
return res;
}
```

Thanks all for the comments. I revised the code to make it easier to read and adjusted the percentage.