public class Solution {
public int maxProfit(int[] prices) {
if (prices == null || prices.length == 0) {
return 0;
}
int low = Integer.MAX_VALUE;
int profits = 0;
for (int i = 0; i < prices.length; i++) {
low = prices[i] < low ? prices[i] : low;
profits = (prices[i] - low) > profits ? (prices[i] - low) : profits;
}
return profits;
}
}
Best Time to Buy and Sell Stock
最新推荐文章于 2022-07-29 20:36:59 发布