Skip to content

Latest commit

 

History

History

121.Best_Time_to_Buy_and_Sell_Stock

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

�## 121. Best Time to Buy and Sell Stock (Medium)

链接

题目:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
代码(github):https://github.com/illuz/leetcode

题意

给一个数组,prices[i] 表示第 i 天的交易值,也就是你在这天买入或卖出的交易值。
你只能买入及卖出一轮,求最大盈利。

分析

只要 profit = prices[sell] - prices[buy] && buy < sell 就行了,遍历一遍,维护 profit 即可。