@@ -0,0 +1,1853 @@
+package leetcode.oj.bestTimeSellAndBuyTheStockII;%0A%0A/**%0A * Created by mark on 2/10/14.%0A */%0A%0A//http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/%0A%0Apublic class Solution %7B%0A//    public int maxProfit(int%5B%5D prices) %7B%0A//        int max = 0;%0A//        int%5B%5D%5B%5D data = new int%5Bprices.length%5D%5Bprices.length%5D;%0A//%0A//        for (int i = 0; i %3C prices.length; i++) %7B%0A//            int ci = i;%0A//            for (int duration = 1; duration %3C prices.length - 1; duration++) %7B%0A//                if (ci %3E= 2 && i == duration) %7B%0A//                    int tmp = data%5B0%5D%5Bduration%5D;%0A//                    int value = prices%5Bci-1%5D - prices%5B0%5D;%0A//                    tmp = tmp - value;%0A//%0A//                    if (tmp %3E max) %7B%0A//                        max = tmp;%0A//                    %7D%0A//%0A//                %7D else %7B%0A//                    int tmp = 0;%0A//                    int j = ci + duration;%0A//                    while (j %3C prices.length) %7B%0A//                        tmp += (prices%5Bj%5D - prices%5Bci%5D);%0A//                        ci = ci + 1 + duration;%0A//                        j = ci + duration;%0A//                    %7D%0A//%0A//                    data%5Bi%5D%5Bduration%5D = tmp;%0A//%0A//                    if (tmp %3E max) %7B%0A//                        max = tmp;%0A//                    %7D%0A//                %7D%0A//            %7D%0A//        %7D%0A//        return max;%0A//    %7D%0A%0A%0A    // the following calculation is under the assumption that we can do the transaction in the same day%0A    // for example , sell 12@TUE and buy 12@TUE%0A    // the above algorithm only support the sell 12@TUE/buy 12@TUE at one day%0A%0A    public int maxProfit(int%5B%5D prices) %7B%0A        int p = 0;%0A        for (int i = 1; i %3C prices.length; ++i) %7B%0A            int delta = prices%5Bi%5D - prices%5Bi - 1%5D;%0A            if (delta %3E 0) %7B%0A                p += delta;%0A            %7D%0A        %7D%0A        return p;%0A    %7D%0A%7D%0A

add code