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

#include <leetcode.h>

静态 Public 成员函数

static int maxProfit (vector< int > &prices)
 

详细描述

在文件 leetcode.h3050 行定义.

成员函数说明

◆ maxProfit()

int leetcode::best_time_to_buy_and_sell_stock_with_cooldown::Solution::maxProfit ( vector< int > &  prices)
static

在文件 leetcode.cpp8632 行定义.

8632 {
8633 if(prices.empty()) {
8634 return 0;
8635 }
8636
8637 const int n = prices.size();
8638 int f0 = -prices[0];
8639 int f1 = 0;
8640 int f2 = 0;
8641 for(int i = 1; i < n; ++i) {
8642 tie(f0, f1, f2) = make_tuple(max(f0, f2 - prices[i]), f0 + prices[i], max(f1, f2));
8643 }
8644
8645 return max(f1, f2);
8646 }

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


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