返回递增长度
dp[0] = 1;
int ans = 1;
for(int i=1;i<len;i++){
dp[i] = 1;
for(int j=0;j<i;j++){
if(nums[j]<nums[i]&&j<i){
dp[i] = Math.max(dp[j]+1,dp[i]);}}
ans = Math.max(ans,dp[i]);
}
return ans;
返回序列
public int[] LIS (int[] arr) {
int n = arr.length;
int[] dp = new int[n];
int[] temp = new int[n+1];
dp[0] = 1;
int len = 1;
temp[1] = arr[0];
for(int i=0;i<n;i++){
if(arr[i]>temp[len]){
temp[++len] = arr[i];
dp[i] = len;
}
else{
int l=0,r = len;
while(l<=r){
int mid = (l + r) >> 1;
if(temp[mid]>=arr[i]){
r = mid-1;
}
else l = mid+1;
}
temp[l] = arr[i];
dp[i] = l;
}
}
int[] res = new int[len];
for (int i = n - 1; i >= 0; i--) {
if (dp[i] == len) {
res[--len] = arr[i];
}
}
return res;