Stock maximize profits 63-

Topic: Suppose the price of a share in chronological order stored in an array, what's largest trading profits once the stock is likely to get much

def stock_max_val(arrys):
    bef_min = arrys[0]
    res = [0]*len(arrys)
    i = 1
    while i<len(arrys):
        if arrys[i]<bef_min:
            bef_min = arrys[i]
        res[i] = arrys[i]-bef_min
        i+=1
    return max(res)

  Note: the number currently stored minimum value before and when traversed sequentially calculates the difference between the current value and the minimum value, the maximum final difference in the array is the maximum profit.

Guess you like

Origin www.cnblogs.com/kingshine007/p/11578654.html