牛客题霸 NC7 买卖股票的最好时机
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC7 买卖股票的最好时机
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
解決方案
Go
func maxProfit(prices []int) int {// write code herevar min int = 1e9max := 0for _, price := range prices {if max < price-min {max = price - min}if min > price {min = price}}return max }參考文章
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的牛客题霸 NC7 买卖股票的最好时机的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客题霸 NC6 二叉树的最大路径和
- 下一篇: 牛客题霸 NC8 二叉树根节点到叶子节点