LeetCode121双指针解法
由 hubdog 于 星期一, 2021-04-19 09:07 发表
class Solution { public int maxProfit(int[] prices) { int maxProfit=0; for (int i=0;i<prices.length;i++){ if (prices[i]<minPrice){ minPrice=prices[i]; } else if (prices[i]-minPrice>maxProfit){ maxProfit=prices[i]-minPrice; } } return maxProfit; } }