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