Best Time to Buy and Sell Stock
Say you have an array for which thei_thelement is the price of a given stock on day_i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
Example 1:
Example 2:
分析
Min,max设置一下,从第二天开始
Last updated