代码随想录算法训练营|第五十天

买卖股票的最佳时机含冷冻期

309. 买卖股票的最佳时机含冷冻期 - 力扣(LeetCode)

代码随想录算法训练营|第五十天_第1张图片

public class Solution {
    public int MaxProfit(int[] prices) {
        if(prices.Length == 0)return 0;
        int[,] dp= new int[prices.Length+1,4];
        dp[0,0] = -prices[0];
        
        for(int i=1;i

买卖股票的最佳时机含手续费

714. 买卖股票的最佳时机含手续费 - 力扣(LeetCode)

和122那题完全一样,就只要卖出时多减去手续费就行
public class Solution {
    public int MaxProfit(int[] prices, int fee) {
        if(prices.Length == 0)return 0;
        int[,] dp = new int[prices.Length,2];
        dp[0,0] = -prices[0];

        for(int i=1;i

你可能感兴趣的:(代码随想录,算法,leetcode)