1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00
LeetCode/cs/best-time-to-buy-and-sell-stock-with-transaction-fee.cs
2024-08-04 23:25:17 +02:00

13 lines
355 B
C#

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;
}
}