# leetcode：122. Best Time to Buy and Sell Stock II（java）解答

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 int maxProfit(int[] prices) {
int maxPro = 0;
int length = prices.length - 1;
for (int i = 0; i < length; i++) {
if (prices[i] < prices[i + 1]) {
maxPro += prices[i + 1] - prices[i];
}
}
return maxPro;
}

#### leetcode122题解

2017-06-05 18:18:50

#### leetCode练习（122）

2016-11-03 14:51:00

#### leetcode-java-122. Best Time to Buy and Sell Stock II

2016-06-26 19:36:25

#### 【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【java】

2017-01-11 11:31:58

#### LeetCode 122 -Best Time to Buy and Sell Stock II ( JAVA )

2016-04-08 21:10:28

#### LeetCode(122) Best Time to Buy and Sell Stock II (Java)

2015-04-19 13:18:34

#### leetcode121、122、123

2017-02-22 19:20:30

#### leetcode刷题。总结，记录，备忘 122

2015-07-26 14:43:22

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

2015-01-26 18:28:17