class Solution { public: int maxProfit(vector &prices) { int max = 0; if (prices.size() <2) {return 0;} int i,j=0; vector minV(prices.size(),0); minV[0] = prices[0]; for(j=1;j{
if ((prices[j] - minV[j-1] ) > max){ max = (prices[j] - minV[j-1] ); } if(prices[j] > prices[j-1]) { minV[j] = prices[j-1]; } else { minV[j] = prices[j]; } } return max; } }; i got this from LC.com Submission Result: Wrong Answer Input: [1,2] Output: 0 Expected: 1 But on my computer it is 1 as return value. confused. 求大神