JAVA
class Solution {
public int maxProfit(int[] prices) {
int profit = 0;
for(int i =0; i<prices.length-1; i++){
if (prices[i+1]>prices[i]) profit += prices[i+1]-prices[i];
}
return profit;
}
}
python
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
for i in range(len(prices)-1):
if prices[i+1]>prices[i]:
profit += prices[i+1]-prices[i]
return profit