122. 买卖股票的最佳时机 I
2/17/24Less than 1 minute
122. 买卖股票的最佳时机 I
简单class Solution {
public int maxProfit(int[] prices) {
int min = Integer.MAX_VALUE;
int res = 0;
for (int price : prices) {
if (price < min) {
min = price;
} else if (price - min > res) {
res = price - min;
}
}
return res;
}
}