动态规划
zonaqiu
这个作者很懒,什么都没留下…
展开
-
300 最长递增子序列
300 最长递增子序列 动态规划 class Solution { public int lengthOfLIS(int[] nums) { int n = nums.length; int[] dp = new int[n]; Arrays.fill(dp,1); dp[0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j &l原创 2021-08-26 16:03:32 · 109 阅读 · 0 评论 -
435 无重叠区间
435 无重叠区间 动态规划(超时) class Solution { public int eraseOverlapIntervals(int[][] intervals) { int n = intervals.length; if (n==0){ return 0; } int[] f = new int[n]; Arrays.fill(f, 1); //对区间按照首节原创 2021-08-26 14:58:33 · 131 阅读 · 0 评论 -
5 最长回文子串
5 最长回文子串 动态规划 class Solution { public String longestPalindrome(String s) { int len=s.length(); if (s.length()<2){ return s; } //dp[i][j]表示s[i,...j]是否是回文串 boolean[][] dp=new boolean[len][len];原创 2021-08-06 13:37:07 · 55 阅读 · 0 评论 -
63 不同路径-02
63 不同路径-02 动态规划 class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int rows = obstacleGrid.length; int colums = obstacleGrid[0].length; int[][] f = new int[rows][colums]; for(int i=0;i<row原创 2021-07-13 20:03:14 · 67 阅读 · 0 评论 -
63不同路径
63不同路径 动态规划01 class Solution { public int uniquePaths(int m, int n) { int[][] f = new int[m][n]; for(int i=0;i<m;i++){ Arrays.fill(f[i],0); } f[0][0] = 1; for(int i=0;i<m;i++){ for原创 2021-07-13 19:07:28 · 51 阅读 · 0 评论 -
123买卖股票的最佳时机-03
123买卖股票的最佳时机-03 动态规划 class Solution { public int maxProfit(int[] prices) { int buy_1 = -prices[0]; int sell_1 = 0; int buy_2 = -prices[0]; int sell_2 = 0; for(int i=1;i<prices.length;i++){ buy_1原创 2021-07-13 16:36:03 · 36 阅读 · 0 评论 -
122 买卖股票的最佳时机-02
122 买卖股票的最佳时机-02 动态规划 class Solution { public int maxProfit(int[] prices) { int dp_0 = 0; int dp_1 = -prices[0]; for(int i=1;i<prices.length;i++){ int tmp_dp_0 = Math.max(dp_0,dp_1+prices[i]);原创 2021-07-10 20:00:33 · 93 阅读 · 1 评论 -
322 零钱兑换
322 零钱兑换 递归版(超时) class Solution { public int coinChange(int[] coins, int amount) { if(amount==0){ return 0; } if(amount<0){ return -1; } int res =Integer.MAX_VALUE; for(int co原创 2021-07-08 23:48:36 · 68 阅读 · 1 评论