problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::best_time_to_buy_and_sell_stock_with_transaction_fee::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int maxProfit (vector< int > &prices, int fee)
 

详细描述

在文件 leetcode.h3058 行定义.

成员函数说明

◆ maxProfit()

int leetcode::best_time_to_buy_and_sell_stock_with_transaction_fee::Solution::maxProfit ( vector< int > &  prices,
int  fee 
)
static

在文件 leetcode.cpp8650 行定义.

8650 {
8651 const int n = prices.size();
8652 vector<int> holding(n);
8653 vector<int> not_holding(n);
8654 not_holding[0] = 0;
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]);
8659 }
8660 return max(not_holding.back(), holding.back());
8661 }

被这些函数引用 leetcode::best_time_to_buy_and_sell_stock_with_transaction_fee::TEST().


该类的文档由以下文件生成: