本文共 1017 字,大约阅读时间需要 3 分钟。
int profit;void calculateprofit(int* prices,int pricesSize,int pos,int shares,int fee,int money){ if(money > profit) profit = money; if(pos < pricesSize) { if(!shares) calculateprofit(prices,pricesSize,pos+1,prices[pos],fee,money-prices[pos]); else calculateprofit(prices,pricesSize,pos+1,0,fee,money+prices[pos]-fee); calculateprofit(prices,pricesSize,pos+1,shares,fee,money); }}int maxProfit(int* prices, int pricesSize, int fee){ profit = 0; calculateprofit(prices,pricesSize,0,0,fee,0); return profit;}
int maxProfit(int* prices, int pricesSize, int fee){ int dp[pricesSize][2],profit = 0,i; dp[0][0] = 0,dp[0][1] = (-prices[0]); for(i=1;i
class Solution { public: int maxProfit(vector & prices, int fee) { int size = prices.size(); int prebuy = -prices[0],presold = 0,nowbuy = 0,nowsold = 0; for(int i=1;i
转载地址:http://fzqvf.baihongyu.com/