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

}