LeetCode:121. 买卖股票的最佳时机(单调栈)
class Solution { public int maxProfit(int[] prices) { int res=0; int MinPrice = Integer.MAX_VALUE; int len = prices.length-1; for(int i=0;i<=len;i++){ if(MinPrice>prices[i]){ MinPrice = prices[i]; } else if((prices[i]-MinPrice)>res){ res = prices[i]-MinPrice; } } return res; } }