```
public class Solution {
public int maxProfit(int[] prices) {
int l = prices.length;
if( l < 2 ) return 0;
int min = Integer.MAX_VALUE, profit=0;
for(int i=0; i<l; i++){
min = ( prices[i] < min) ? prices[i] : min;
profit = ( prices[i] - min > profit ) ? prices[i] - min : profit;
}
return profit;
}
}
```