@@ -0,0 +1,887 @@
+/**%0A *%09Say you have an array for which the ith element is the price of a given stock on day i.%0A *%0A *%09Design an algorithm to find the maximum profit.%0A *%09You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times).%0A * %09However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).%0A *%0A *  Author: matao%0A */%0A%0Apublic class BestTimeToBuyAndSellStockII %7B%0A%09public static int maxProfit(int%5B%5D prices) %7B%0A%09%09int profit = 0;%0A        for(int i = 0; i %3C prices.length-1; i++) %7B%0A        %09int diff = prices%5Bi + 1%5D - prices%5Bi%5D;%0A        %09if (diff %3E 0) %7B%0A        %09%09profit += diff;%0A        %09%7D%0A        %7D%0A        return profit;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09int%5B%5D prices = %7B2, 1, 2, 0, 1%7D;%0A    %09int maxProfit = maxProfit(prices);%0A    %09System.out.println(maxProfit);%0A    %7D%0A%7D

add Best Time to Buy and Sell Stock II solution