LeetCode--300. 最长上升子序列(java)

在这里插入图片描述
推荐题解

class Solution {
	public int lengthOfLIS(int[] nums) {
		if(nums == null || nums.length == 0) return 0;
		int[] dp = new int[nums.length];
		Arrays.fill(dp, 1);
		int maxLength = Integer.MIN_VALUE;
		for(int i = 0;i < nums.length;i++) {
			for(int j = 0;j < i;j++) {
				if(nums[j] < nums[i]) {
					dp[i] = Math.max(dp[j] + 1, dp[i]);
				}
			}
			if(dp[i] > maxLength) maxLength = dp[i];
		}
		return maxLength;
    }
}
发布了97 篇原创文章 · 获赞 11 · 访问量 4991

猜你喜欢

转载自blog.csdn.net/QinLaoDeMaChu/article/details/104291672
今日推荐