第九章 动态规划part10
- 121. 买卖股票的最佳时机
- 122.买卖股票的最佳时机II
class Solution {
public int maxProfit(int[] prices) {
int maxProfit = 0;
int minPrice = Integer.MAX_VALUE;
for(int price: prices){
if(price < minPrice){
minPrice = price;
} else if(price - minPrice > maxProfit){
maxProfit = price - minPrice;
}
}
return maxProfit;
}
}