public int maxProfit(int[] prices) {
        int minPrices = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int i : prices) {
            minPrices = Math.min(minPrices, i);
            maxProfit = Math.max(maxProfit, i - minPrices);
        }
        return maxProfit;
    }