1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

cs: add «714. Best Time to Buy and Sell Stock with Transaction Fee»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-08-04 23:25:17 +02:00
parent 1ae0cb4b89
commit bb796ab51f
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,13 @@
public class Solution {
public int MaxProfit(int[] prices, int fee) {
var profit = 0;
var buyPrice = prices[0];
for (var i = 1; i < prices.Length; ++i) {
profit = Math.Max(profit, prices[i] - buyPrice - fee);
buyPrice = Math.Min(buyPrice, prices[i] - profit);
}
return profit;
}
}