LeetCode121双指针解法
Submitted by hubdog on Mon, 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; } }