300. 最长递增子序列 - 力扣(LeetCode)
class Solution {public int lengthOfLIS(int[] nums) {int[] dp = new int[nums.length];dp[0] = 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[j],dp[i]);}}dp[i] += 1;}int result = 0;for(int i=0;i<nums.length;i++){result = Math.max(dp[i],result);}return result;}
}
674. 最长连续递增序列 - 力扣(LeetCode)
class Solution {public int findLengthOfLCIS(int[] nums) {// int nowLength = 1;// int maxLength = 0;// for(int i=1;i<nums.length;i++){// if(nums[i] > nums[i-1]){// nowLength++;// }else{// maxLength = Math.max(nowLength,maxLength);// nowLength = 1;// }// }// maxLength = Math.max(nowLength,maxLength);// return maxLength;int[] dp = new int[nums.length];dp[0] = 1;int result = 1;for(int i=1;i<nums.length;i++){if(nums[i] > nums[i-1]){dp[i] = dp[i-1] + 1;}else{dp[i] = 1;}result = Math.max(result,dp[i]);}return result;}
}
718. 最长重复子数组 - 力扣(LeetCode)
class Solution {public int findLength(int[] nums1, int[] nums2) {int[][] dp = new int[nums1.length][nums2.length];int result = 0;for(int i=0;i<nums1.length;i++){if(nums1[i] == nums2[0]){dp[i][0] = 1;result = 1;}}for(int j=0;j<nums2.length;j++){if(nums1[0] == nums2[j]){dp[0][j] = 1;result = 1;}}for(int i=1;i<nums1.length;i++){for (int j=1;j<nums2.length;j++){if(nums1[i] == nums2[j]){dp[i][j] = dp[i-1][j-1]+1;}result = Math.max(result,dp[i][j]);}}return result;}
}