[Codility] [9–1] MaxProfit (score 66%)
Dec 15, 2021
【Lesson 9–1】: MaxProfit 今日扣昨日得到營餘,取營餘最大者 (66%)
public static int MaxProfit(int[] A){int MaxProfit = 0;for (int i = A.Length - 1; i > 0; i--){for (int j = i-1; j >= 0; j--){if ((A[i] - A[j]) > MaxProfit)MaxProfit = (A[i] - A[j]);}}return MaxProfit > 0 ? MaxProfit : 0;}