Create Best Time to Buy and Sell Stock2

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.

有一个数组，求其中连续数组的最大和。联想到该题，股票的涨势最大值是否可以转换为一个一个的高度差所组成的数组对这个数组求连续的最大值。