摘要: 动态规划 class Solution { public int findLength(int[] nums1, int[] nums2) { /** * dp[i][j]定义为nums1[i - 1] == nums2[j - 1]时的最长重复子数组的长度 * 因为i - 1必须要大于等于0,所以 阅读全文
posted @ 2022-02-28 23:03 振袖秋枫问红叶 阅读(23) 评论(0) 推荐(0)
摘要: 动态规划 import java.util.Arrays; class Solution { public int findLengthOfLCIS(int[] nums) { /** * dp[i]定义为以nums[i]结尾的最长连续递增子序列 * 每个数字自己都可以构成一个序列,因此初始化长度都 阅读全文
posted @ 2022-02-28 21:58 振袖秋枫问红叶 阅读(33) 评论(0) 推荐(0)
摘要: 动态规划 import java.util.Arrays; class Solution { public int lengthOfLIS(int[] nums) { /** * dp[i]定义为以nums[i]结尾的最长递增子序列 * 每个数字自己都可以构成一个序列,因此初始化长度都为1 */ i 阅读全文
posted @ 2022-02-28 21:17 振袖秋枫问红叶 阅读(30) 评论(0) 推荐(0)
摘要: 动态规划 class Solution { public int maxProfit(int[] prices) { if (prices.length == 1){ return 0; } int[][] dp = new int[prices.length][4]; dp[0][0] = -pr 阅读全文
posted @ 2022-02-28 19:56 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要: 动态规划 class Solution { public int maxProfit(int k, int[] prices) { if (prices.length == 0){ return 0; } int[][] dp = new int[prices.length][2 * k + 1]; 阅读全文
posted @ 2022-02-28 17:05 振袖秋枫问红叶 阅读(30) 评论(0) 推荐(0)
摘要: 动态规划 class Solution { public int maxProfit(int[] prices) { int[][] dp = new int[prices.length][5]; dp[0][0] = 0; dp[0][1] = -prices[0]; dp[0][2] = 0; 阅读全文
posted @ 2022-02-28 16:23 振袖秋枫问红叶 阅读(27) 评论(0) 推荐(0)
摘要: 动态规划 class Solution { public int maxProfit(int[] prices) { /** * 因为只能买一次,因此无法确定哪天买了还有每天的持股状态,需要定义一个二维数组分别存储持不持有该股票的利润 * dp[i][0]为第i天持有该股票的利润 * dp[i][1 阅读全文
posted @ 2022-02-28 13:24 振袖秋枫问红叶 阅读(34) 评论(0) 推荐(0)