LeetCode刷题记57
121. 买卖股票的最佳时机
class Solution {
public int maxProfit(int[] prices) {
int ans = 0;
if (prices.length == 0) return ans;
int min_val = prices[0];
for (int i = 1; i < prices.length; i ++) {
ans = Math.max(ans, prices[i] - min_val);
min_val = Math.min(min_val, prices[i]);
}
return ans;
}
}
简单题,偷懒用的
4/5
57/150