Best Time to Buy and Sell Stock with Transaction Fee LeetCode solution in C++

1
class Solution {
2
public:
3
int maxProfit(vector<int> &prices, int fee) {
4
int buy = INT_MIN;
5
int sell = 0;
6

7
for (int price : prices) {
8
buy = max(buy, sell - price);
9
sell = max(sell, buy + price - fee);
10
}
11

12
return sell;
13
}
14
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0