import java.util.Arrays;
public class LongestSeq {
public static void main(String[] args) {
System.out.println(lengthOfLIS(new int[]{10, 9, 2, 5, 3, 7, 101, 18}));
}
private static int lengthOfLIS(int[] nums) {
int[] dp = new int[nums.length];
int max = 1;
Arrays.fill(dp, 1);
for (int i = 1; i < nums.length; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
max = Math.max(max, dp[i]);
}
return max;
}
}
LeetCode300. 最长递增子序列
最新推荐文章于 2024-09-27 11:50:10 发布