@@ -0,0 +1,1113 @@
+public class Solution %7B%0A    public int maxProfit(int%5B%5D prices) %7B%0A        if(prices==null %7C%7C prices.length==0)%7B%0A            return 0;%0A        %7D%0A        int%5B%5D diff1 = new int%5Bprices.length%5D;%0A        diff1%5B0%5D = 0;%0A        for(int i=1;i%3Cprices.length;i++)%7B%0A            diff1%5Bi%5D = prices%5Bi%5D-prices%5B0%5D;%0A        %7D%0A        // for(int i=0;i%3Cdiff1.length;i++)%7B%0A        //     System.out.println(diff1%5Bi%5D);%0A        // %7D%0A        int max = Integer.MIN_VALUE;%0A        for(int i=0;i%3Cdiff1.length;i++)%7B%0A            int max1=0;%0A            int max2 =0;%0A%0A            int res = findMax(diff1,i+1,diff1.length-1);%0A            max1 = res%3E0? res:max1;%0A            res = findMax(diff1,0,i);%0A            max2 = res%3E0? res:max2;%0A            max = Math.max(max,max1+max2);%0A%0A        %7D%0A        return max%3E0? max:0;%0A    %7D%0A    public int findMax(int%5B%5D diff1, int left, int right)%7B%0A        if(left%3E=right)%7B%0A            return 0;%0A        %7D%0A        int max = 0;%0A        for(int i=left;i%3Cright;i++)%7B%0A            for(int j=i+1;j%3C=right;j++)%7B%0A                max = Math.max(max,diff1%5Bj%5D-diff1%5Bi%5D);%0A            %7D%0A        %7D%0A        return max;%0A    %7D%0A%7D

The solution for 123 TLE