这个题实际理解下来,意思是,已经知道i天内股票的价格,所以当然是只要有正的差价就卖。
贪心算法的应用
class Solution {
public int maxProfit(int[] prices) {
int profit=0;
for(int i=1;i<prices.length;i++){
if(prices[i]>prices[i-1]){
profit+=prices[i]-prices[i-1];
}
}
return profit;
}
}