class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) { return 0; } int result = 0; int min = prices[0]; for (int i = 1; i < prices.length; ++ i) { result = Math.max(prices[i] - min, result); min = Math.min(prices[i], min); } return result; } }
LeetCode - 121. 买卖股票的最佳时机
猜你喜欢
转载自blog.51cto.com/tianyiya/2174490
今日推荐
周排行