class Solution {
    // 找某个元素的右边的元素的最大值,作差,比较差的大小,暴力法会超时
    // 对于某一个具体的日子,在当天卖出股票所能获得的最大值,是当前的股票价格减去之前出现过的最小值
    // 求整个过程的最大值
    public int maxProfit(int[] prices) {
        int max = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i]  < min) {
                min = prices[i];
            }
            if (prices[i] - min > max) {
                max = prices[i] - min;
                
            }
        }
        return max;
    }
}