@@ -0,0 +1,1012 @@
+/***%0A * Say you have an array for which the ith element is the price of a given stock on day i.%0A * Design an algorithm to find the maximum profit. You may complete at most two transactions.%0A */%0Apublic class Solution %7B%0A    public int maxProfit(int%5B%5D prices) %7B%0A        int n = prices.length;%0A        if (n == 0) return 0;%0A%0A        int f%5B%5D = new int %5Bn%5D;%0A        int g%5B%5D = new int %5Bn%5D;%0A%0A        int pmin = prices%5B0%5D;%0A        for (int i = 1; i %3C n; i++) %7B%0A            if (pmin %3E prices%5Bi%5D)%0A                pmin = prices%5Bi%5D;%0A            f%5Bi%5D = prices%5Bi%5D - pmin %3E f%5Bi - 1%5D ? prices%5Bi%5D - pmin : f%5Bi - 1%5D;%0A        %7D%0A        int pmax = prices%5Bn - 1%5D;%0A        for (int i = n - 2; i %3E= 0; i--) %7B%0A            if (pmax %3C prices%5Bi%5D)%0A                pmax = prices%5Bi%5D;%0A            g%5Bi%5D = pmax - prices%5Bi%5D %3E g%5Bi + 1%5D ? pmax - prices%5Bi%5D : g%5Bi + 1%5D;%0A        %7D%0A        int mprofit = 0;%0A        for (int i = 0; i %3C n; i++)%0A            if (mprofit %3C f%5Bi%5D + g%5Bi%5D)%0A                mprofit = f%5Bi%5D + g%5Bi%5D;%0A        return mprofit;%0A    %7D%0A%7D%0A

add BestTimetoBuyandSellStockIII.java