import java.util.*;


public class Solution {
    /**
     * 
     * @param prices int整型一维数组 
     * @return int整型
     */
    public int maxProfit (int[] prices) {
        // write code here
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int val : prices) {
            if (val < min) min = val;
            else max = Math.max(max, val - min);
        }
        return max;
    }
}