```
public class Solution {
public int maxProfit(int[] prices) {
if (prices.length == 0 | prices.length == 1)
return 0;
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE, profit = 0;
for (int x = 0; x < prices.length; x++){
if ((prices[x] - min) > profit){
profit = prices [x] - min;
max = prices[x];
}
if (prices[x] < min)
min = prices[x];
}
return profit;
}
}
```