index
title: 股票的最大利润 date: 2019-08-21T11:00:41+08:00 draft: false categories: offer
题目
一只股票在某些时间节点的价格为{9,11,8,5,7,12,16,14}
。如果我们能在价格为 5 的时候买入并在价格为 16 时卖出,则能获得最大的利润为 11.
解题思路
要先买入才能卖出,先找最低价格点
再找最低价格之后的最高价格,用
maxProfit
表示最大利润
Last updated
Was this helpful?