题解 | #最长上升子序列(一)#
最长上升子序列(一)
http://www.nowcoder.com/practice/5f65ccbb025240bd8458eb6479c2612e
循环寻找最大的那个即可
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] array = new int[n];
for(int i = 0; i < n; i++){
array[i] = scan.nextInt();
}
int[] dp = new int[n];
Arrays.fill(dp,1);
int res = 1;
for(int i = 1; i < n;i++){
for(int j = 0; j < i;j++){
if(array[i] > array[j]){
dp[i] = Math.max(dp[i],dp[j] + 1);
}
res = Math.max(res,dp[i]);
}
}
System.out.println(res);
}
}