122. 买卖股票的最佳时机 I
小于 1 分钟
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;
}
}
Powered by Waline v2.15.5