class Solution {
public int maxProfit(int[] prices) {
int minv = prices[0];
int ans = 0;
for(int i = 1; i < prices.length; i ++ ){
ans = Math.max(ans, prices[i] - minv);
minv = Math.min(minv, prices[i]);
}
return ans;
}
}