```
public class Solution {
public int lengthOfLIS(int[] nums) {
int N = 0, idx, x;
for(int i = 0; i < nums.length; i++) {
x = nums[i];
if (N < 1 || x > nums[N-1]) {
nums[N++] = x;
} else if ((idx = Arrays.binarySearch(nums, 0, N, x)) < 0) {
nums[-(idx + 1)] = x;
}
}
return N;
}
}
```

Re-use the array given as input for storing the tails.