#include <leetcode.h>
|
static int | maxProfit (vector< int > &prices, int fee) |
|
◆ maxProfit()
int leetcode::best_time_to_buy_and_sell_stock_with_transaction_fee::Solution::maxProfit |
( |
vector< int > & |
prices, |
|
|
int |
fee |
|
) |
| |
|
static |
在文件 leetcode.cpp 第 8650 行定义.
8651 const int n = prices.size();
8652 vector<int> holding(n);
8653 vector<int> not_holding(n);
8655 holding[0] = -prices[0];
8656 for(
int i = 1; i < n; i++) {
8657 not_holding[i] = max(not_holding[i - 1], holding[i - 1] + prices[i] - fee);
8658 holding[i] = max(holding[i - 1], not_holding[i - 1] - prices[i]);
8660 return max(not_holding.back(), holding.back());
被这些函数引用 leetcode::best_time_to_buy_and_sell_stock_with_transaction_fee::TEST().
该类的文档由以下文件生成: