- Leetcode PHP题解--D109 122. Best T
- leetcode:122. Best Time to Buy a
- [数组]122. Best Time to Buy and Se
- Leetcode122-Best Time to Buy and
- 跟我一起刷leetCode算法题9之Best Time to B
- 121. Best Time to Buy and Sell S
- 【2019-07-30】leetcode(121-130)
- 121. Best Time to Buy and Sell S
- BestTimeToBuyAndSellStock with c
- [2018-11-18] [LeetCode-Week11] 1
You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times).
这题可以买任意多次交易。
有点上帝视角的意思。
public int maxProfit(int[] prices) {
if (prices.length < 2) return 0;
int total = 0;
for (int i = 1; i < prices.length; i++) {
if (prices[i] - prices[i - 1] > 0) {
total += prices[i] - prices[i - 1];
}
}
return total;
}
ref:
http://blog.csdn.net/linhuanmars/article/details/23164149
网友评论