社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
题目来源:
https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/
题目描述:
代码如下:
class Solution {
public int maxProfit(int[] prices) {
int result = 0, buyMin = Integer.MAX_VALUE;
for (int price : prices) {
buyMin = Math.min(buyMin, price);
result = Math.max(result, price - buyMin);
}
return result;
}
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!