代码:
class Solution {
public int maxProfit(int[] prices) {
if(prices.length==0) return 0;
int minV = prices[0];
int maxP = 0;
for (int i = 1; i < prices.length; i++) {
maxP = Math.max(maxP, prices[i] - minV);
minV = Math.min(minV, prices[i]);
}
return maxP;
}
}