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 (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.
給你一個陣列代表,每個元素代表第i天的物價。
如果你只能得到一次的價差(只做一次買和賣),請設計一個演算法找到最大利潤。
注意你不能在買之前就賣一個東西。
LeetCode
C++