6 3 3 5 0 0 3
123
static int maxProfit2(int[] p){int buy1=Integer.MIN_VALUE,buy2=Integer.MIN_VALUE;int sell1=0,sell2=0;for(int x:p){buy1=Math.max(buy1,-x);sell1=Math.max(sell1,buy1+x);buy2=Math.max(buy2,sell1-x);sell2=Math.max(sell2,buy2+x);}return sell2;}
static int maxProfit2(int[] p){int buy1=Integer.MIN_VALUE,buy2=Integer.MIN_VALUE;int sell1=0,sell2=0;for(int x:p){buy1=Math.max(buy1,-x);sell1=Math.max(sell1,buy1+x);buy2=Math.max(buy2,sell1-x);sell2=Math.max(sell2,buy2+x);}return sell2;}