链接点我
题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ca98fa1a8319d866aed35355a457136d.png)
思路
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ed8f130877b86ec80e7eab420b35dea5.png)
public int maxProfit(int[] prices) {
if(prices == null || prices.length == 0){
return 0;
}
int maxProfit = 0;
for(int i = 0; i < prices.length-1; i++){
if(prices[i+1] > prices[i]){
maxProfit += prices[i+1]-prices[i];
}
}
return maxProfit;
}