[抄题]:
If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Input: [7, 1, 5, 3, 6, 4] Output: 5 max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)
[一句话思路]:贪心算法。不要用数组i,j角标,直接用min, profit表示价格,更方便。
[画图]:
[一刷]:
min, profit都记得要初始化
[总结]:
[复杂度]:
n/1
[英文数据结构]:
[其他解法]:
[题目变变变]:
maximum subarray最大求和子数组