Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).
Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
給你一個陣列,每個元素代表第i天的物價。
設計一個演算法找到最大的利潤,你應該會完成許多次的價差交易(買和賣很多次,但一次的亮只能買賣一個)。
注意:你不應該一次進行多個交易(你必須先買才賣)。
LeetCode
C++