# Middle-题目4：122. Best Time to Buy and Sell Stock II

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 (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

public class Solution {
public int maxProfit(int[] prices) {
int profit=0;
int l=prices.length-1;
for(int i=0;i<l;i++) {
if(prices[i+1]>=prices[i])
profit+=prices[i+1]-prices[i];
}
return profit;
}
}

2ms,beats 15.31%，众数2ms,76.17%
Cmershen的碎碎念：

#### Best Time to Buy and Sell Stock II -- LeetCode

2014-04-09 05:33:51

#### 【Leetcode】：122. Best Time to Buy and Sell Stock II 问题 in JAVA

2016-04-19 15:02:49

#### Leetcode_122_Best Time to Buy and Sell Stock II

2015-01-26 18:28:17

#### leetcode_c++：Best Time to Buy and Sell Stock II（122）

2016-06-10 23:19:48

#### 【LeetCode】【Python题解】Best Time to Buy and Sell Stock II

2014-07-24 10:11:44

#### LeetCode -- Best Time to Buy and Sell Stock II （贪心策略，差分序列）

2014-05-27 15:44:01

#### Best Time to Buy and Sell Stock -- LeetCode

2014-04-09 05:33:32

#### leetcode【121+122+123 best time to buy and sell stock】【python】

2016-09-12 21:04:35

#### Best Time to Buy and Sell Stock III -- LeetCode

2014-04-09 05:34:05

#### 122. Best Time to Buy and Sell Stock II

2014-03-09 10:29:03