Leetcode — 顶级面试 150–121. 买卖股票的最佳时机
原文英文,约500词,阅读约需2分钟。发表于: 。It’s an easy problem with the description being: You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single...
给定一个股票价格数组,选择一天买入,未来某天卖出以最大化利润。如果无法获利,返回0。示例:输入[7,1,5,3,6,4],输出5(在第2天买入,第5天卖出)。通过遍历数组更新最小值和最大值,计算利润差。