```
public static int maxProfit(int[] prices) {
int profit = 0;
for (int i = 0; i < prices.length - 1; i++) {
int j = i + 1;
while (j < prices.length && prices[i] < prices[j]) {
profit = Math.max(profit, prices[j] - prices[i]);
j++;
}
}
return profit;
}
```