Leetcode Algorithms -- Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock (Medium)
Description
Say you have an array for which the ith 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.
Analysis
只有交易一次,求最大收益值。维护当前最小值,不断更新最大收益
My Solution
1 | //C++ |