문제: app.codility.com/programmers/lessons/9-maximum_slice_problem/max_profit/
MaxProfit coding task - Learn to Code - Codility
Given a log of stock prices compute the maximum possible earning.
app.codility.com
if (A.Length <= 1)
return 0;
int maxProfit = 0;
int nowProfit = 0;
int minValue = A[0];
for (int i = 1; i < A.Length; i++)
{
nowProfit = A[i] - minValue;
if (maxProfit < nowProfit)
{
maxProfit = nowProfit;
}
if (minValue > A[i])
minValue = A[i];
}
if (maxProfit < 0)
return 0;
return maxProfit;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson10. CountFactors (C#) (0) | 2020.11.20 |
---|---|
[Codility] Lesson9. MaxSliceSum (C#) (0) | 2020.11.20 |
[Codility] Lesson9. MaxDoubleSliceSum (C#) (0) | 2020.11.20 |
[Codility] Lesson8. EquiLeader (C#) (0) | 2020.11.20 |
[Codility] Lesson8. Dominator (C#) (0) | 2020.11.20 |