URL: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Signed-off-by: Matej Focko <me@mfocko.xyz>
13 lines
247 B
Java
13 lines
247 B
Java
class Solution {
|
|
public int maxProfit(int[] prices) {
|
|
var profit = 0;
|
|
|
|
for (var i = 1; i < prices.length; ++i) {
|
|
if (prices[i] > prices[i - 1]) {
|
|
profit += prices[i] - prices[i - 1];
|
|
}
|
|
}
|
|
|
|
return profit;
|
|
}
|
|
}
|