package JianZhioffer;
// 假设把某股票的价格按照时间先后顺序存储在数组中,请问买卖该股票一次可能获得的最大利润是多少?


public class test63 {
    public static void main(String[] args) {
        int []prices={7,6,4,3,1};
        System.out.println(maxProfit(prices));    
    }
    public static int maxProfit(int[] prices) {
        if(prices.length==0){
            return 0;
        }
        int []dp=new int[prices.length];
        int cost=Integer.MAX_VALUE,profit=0;
        for(int i=0;i<prices.length;i++){
            cost=Math.min(cost, prices[i]);
            profit=Math.max(profit, prices[i]-cost);
        }
        return profit;
    }

    
}