122. Best Time to Buy and Sell Stock II
Posted 我的名字叫周周
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了122. Best Time to Buy and Sell Stock II相关的知识,希望对你有一定的参考价值。
/* * 122. Best Time to Buy and Sell Stock II * 第二题,可以进行无限次,所以只要大于0的都加上 */ public int maxProfit2(int[] prices) { if (prices == null || prices.length == 0 || prices.length == 1) return 0; int res = 0; int low = prices[0]; for (int i = 1; i < prices.length; i++) { if (prices[i] > low) { res = res + prices[i] - low; } low = prices[i]; } return res; }
以上是关于122. Best Time to Buy and Sell Stock II的主要内容,如果未能解决你的问题,请参考以下文章
122. Best Time to Buy and Sell Stock II
LeetCode 122. Best Time to Buy and Sell Stock II
!!!!!122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock II