代码随想录算法训练营day52 300.递增子序列 674.最长连续递增子序列 718.最长重复子数组

题目链接300.递增子序列

复制代码
class Solution {
    public int lengthOfLIS(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        for(int i = 0; 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);
                }
            }
        }
        int res = 0;
        for(int i = 0; i < nums.length; i++){
            res = Math.max(res, dp[i]);
        }
        return res;        
    }
}

题目链接674.最长连续递增子序列

复制代码
class Solution {
    public int findLengthOfLCIS(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        int res = 1;
        for(int i = 1; i < nums.length; i++){
            if(nums[i] > nums[i-1]){
                dp[i] = Math.max(dp[i], dp[i-1] + 1);
            }
            res = Math.max(res, dp[i]);
        }
        return res;
    }
}

题目链接718.最长重复子数组

复制代码
class Solution {
    public int findLength(int[] nums1, int[] nums2) {
        int res = 0;
        int[][] dp = new int[nums1.length+1][nums2.length+1];
        for(int i = 1; i <= nums1.length; i++){
            for(int j = 1; j <=nums2.length; j++){
                if(nums1[i-1] == nums2[j-1]){
                    dp[i][j] = Math.max(dp[i][j], dp[i-1][j-1] + 1);
                }
                res = Math.max(res, dp[i][j]);
            }
        }
        return res;
    }
}
相关推荐
星星火柴93611 分钟前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
艾莉丝努力练剑1 小时前
【洛谷刷题】用C语言和C++做一些入门题,练习洛谷IDE模式:分支机构(一)
c语言·开发语言·数据结构·c++·学习·算法
C++、Java和Python的菜鸟3 小时前
第六章 统计初步
算法·机器学习·概率论
Cx330❀3 小时前
【数据结构初阶】--排序(五):计数排序,排序算法复杂度对比和稳定性分析
c语言·数据结构·经验分享·笔记·算法·排序算法
散1123 小时前
01数据结构-Prim算法
数据结构·算法·图论
起个昵称吧3 小时前
线程相关编程、线程间通信、互斥锁
linux·算法
myzzb4 小时前
基于uiautomation的自动化流程RPA开源开发演示
运维·python·学习·算法·自动化·rpa
旺小仔.4 小时前
双指针和codetop复习
数据结构·c++·算法
jingfeng5144 小时前
C++ STL-string类底层实现
前端·c++·算法
雲墨款哥5 小时前
JS算法练习-Day10-判断单调数列
前端·javascript·算法