public static int maxProfit(int[] prices) {
        int profit = 0;
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < prices.length; i++) {
            profit = profit < prices[i] - min ? prices[i] - min : profit;
            min = min > prices[i] ? prices[i] : min; 
        }

        return profit;
    }