121-best-time-to-buy-and-sell-stock
买卖股票最佳时间
思路
这题思路是遍历数组同时记录最小的数,然后遇到比他大的数和他相减与最大利润相比取最大值,遇到比自己小的数就吧最小值替换成那该数
go语言实现
1 | func maxProfit(prices []int) int { |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment