public static int maxProfit(int[] prices) {
		if(prices.length <= 1) return 0;
		
		int[] profits = new int[prices.length]; 
        int min = prices[0], maxPro = profits[0] = 0;
        for(int i = 1; i < prices.length; i++){
        	if(prices[i] - min > maxPro) maxPro = prices[i] - min;
        	if(prices[i] < min) min = prices[i];
        	profits[i] = maxPro;
        }
        
        int max = prices[prices.length - 1];
        int res = maxPro;
        maxPro = 0;
        for(int i = prices.length - 2; i >= 0; i--){
        	if(max - prices[i] > maxPro) maxPro = max - prices[i];
        	if(prices[i] > max) max = prices[i];
        	if(i > 0){
        		if(maxPro + profits[i - 1] > res) res = maxPro + profits[i - 1];
        	}
        }
        return res;
	}