#
#
# @param prices int整型一维数组
# @return int整型
# 贪心算法
class Solution:
def maxProfit(self , prices ):
# write code here
# 初始化最大收益
mx = 0
# 设置初始购买价格
mn = prices[0]
# 循环遍历
for i in prices:
mx = max(mx, i - mn) # 更新最大收益
mn = min(i, mn) # 更新最小购买价格
return mx

京公网安备 11010502036488号