上一页 1 2 3 4 5 6 7 8 9 10 ··· 36 下一页
摘要: 动态规划 class Solution { public int maxUncrossedLines(int[] nums1, int[] nums2) { /** * 和《1143. 最长公共子序列》一样 */ int[][] dp = new int[nums1.length + 1][nums 阅读全文
posted @ 2022-03-01 09:59 振袖秋枫问红叶 阅读(24) 评论(0) 推荐(0)
摘要: 动态规划 class Solution { public int longestCommonSubsequence(String text1, String text2) { /** * dp[i][j]定义为text1[i - 1] == text2[j - 1]时的公共子序列的最大长度 */ i 阅读全文
posted @ 2022-03-01 09:52 振袖秋枫问红叶 阅读(25) 评论(0) 推荐(0)
摘要: 动态规划 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)
摘要: 贪心 class Solution { int num = 0; public int minCameraCover(TreeNode root) { /** * 如果根节点未被监视,需要单独放一个摄像头 */ if (dfs(root) == 0){ num++; } return num; } 阅读全文
posted @ 2022-02-27 11:08 振袖秋枫问红叶 阅读(50) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 36 下一页