@@ -0,0 +1,1105 @@
+/*%0ASay you have an array for which the ith element is the price of a given stock on day i.%0A%0ADesign an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).%0A%0A*/%0A%0Aimport java.util.*;%0A%0Apublic class BestTimetoBuyandSellStockII %7B%0A%09public static int maxProfit(int%5B%5D prices) %7B%0A        if(prices.length%3C=0) return 0;%0A        int l = prices%5B0%5D;%0A        int res = 0;%0A        for(int i = 1; i %3C prices.length; i++)%7B%0A            if(prices%5Bi%5D %3E l)%7B%0A                res += prices%5Bi%5D-l;%0A            %7D%0A            l = prices%5Bi%5D;%0A        %7D%0A        return res;%0A    %7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09int%5B%5D nums1 = new int%5B%5D %7B1, 2, 3, 0, 2, 7%7D;%0A        System.out.println(%22Array: %22);%0A%09%09for(int i=0; i %3C nums1.length; i++)%7B%0A%09%09%09System.out.print(nums1%5Bi%5D + %22 %22);%0A%09%09%7D%0A        System.out.println();%0A%09%09int res = maxProfit(nums1);%0A        System.out.println(%22Maximum profit: %22 + res);%0A%09%09return;%0A%09%7D%09%0A%7D%0A

add iterately