/* * @lc app=leetcode id=123 lang=java * * [123] Best Time to Buy and Sell Stock III */ // @lc code=start class Solution { public int maxProfit(int[] prices) { int[] ldp = new int[prices.length]; int[] rdp = new int[prices.length]; for(int i=0; i=0; i--) { maxProfit = Math.max(maxProfit, rmax - prices[i]); rmax = Math.max(rmax, prices[i]); rdp[i] = maxProfit; } int profit = ldp[ldp.length-1]; for(int i=0; i