import java.util.*;


public class Solution {
    /**
     * 
     * @param prices int整型一维数组 
     * @return int整型
     */
    public int maxProfit (int[] prices) {
        // write code here
        int[] array = new int[prices.length];
        int minValue = prices[0];
        for(int i=0;i<prices.length;i++){
            if(prices[i] < minValue){
                minValue = prices[i];
            }
            array[i] = minValue;
        }
        int profit = Integer.MIN_VALUE;
        for(int i=0;i<prices.length;i++){
            profit = Math.max(profit, prices[i]-array[i]);
        }
        return profit;
    }
}