题目地址:链接
思路: 遍历时记录最小值,当前值减去历史最小值
function maxProfit(prices: number[]): number {
let ans = 0
let lastMin = prices[0]
for(const price of prices) {
lastMin = Math.min(lastMin, price)
ans = Math.max(ans, price - lastMin)
}
return ans
};
8万+

被折叠的 条评论
为什么被折叠?



