最强解析面试题:best-time-to-buy-and-sell-stock
文章讲解 “ best-time-to-buy-and-sell-stock ” 经典面试题,包含思路及源码,及解惑!
题目
Say you have an array for which the i th element
is the price of a given stock on day i.
If you were only permitted to complete at most one transaction
(ie, buy one and sell one share of the stock),
design an algorithm to find the maximum profit.
中文描述:
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算
本文详细探讨了面试常考题「best-time-to-buy-and-sell-stock」,通过示例解释了如何在最多完成一次交易的情况下,找到能获得的最大利润。核心思路是记录股票价格序列中卖出天前的最小价格,从而找到最大差值。
订阅专栏 解锁全文
156

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



