Best Time to Buy and Sell Stock
Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.
Find the maximum profit from one buy and one sell of a stock price series.
Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.
Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.
Find the maximum profit from one buy and one sell of a stock price series.