Here is my code -

```
public class Solution {
public int maxProfit(int[] prices) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
if (prices.length == 0 ) return 0;
int min = prices[0];
int max = 0;
for (int i = 1; i<prices.length;i++){
if (prices[i] < min)
min = prices[i];
int diff = prices[i] - min;
if (diff > max){
max = diff;
}
}
return max;
}
```

}