@@ -0,0 +1,2593 @@
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Created by mtwtm on 2016/3/21.%0A */%0Apublic class Helper %7B%0A    private class Permutation %7B%0A        private List%3CInteger%3E list;%0A        private boolean isIncrease;%0A        Permutation(int size, boolean isIncrease) %7B%0A            this.isIncrease = isIncrease;%0A            list = new ArrayList%3C%3E();%0A            int start = isIncrease ? 0 : size-1;%0A            int end = isIncrease ? size : -1;%0A            int increment = isIncrease ? 1 : -1;%0A            for(int i = start ; i != end ; i+=increment) %7B%0A                list.add(i);%0A            %7D%0A        %7D%0A        private int swapIndex(int comparingIndex) %7B%0A            int index = list.size()-1;%0A            boolean isSorted = isIncrease ? list.get(index) %3C= list.get(comparingIndex) : list.get(index) %3E= list.get(comparingIndex);%0A            while(isSorted) %7B%0A                index--;%0A                isSorted = isIncrease ? list.get(index) %3C= list.get(comparingIndex) : list.get(index) %3E= list.get(comparingIndex);%0A            %7D%0A            return index;%0A        %7D%0A        private int sortedCount() %7B%0A            int count = 1;%0A            boolean isSorted = isIncrease ? list.get(list.size()-1-count+1) %3C= list.get(list.size()-1-count) : list.get(list.size()-1-count+1) %3E= list.get(list.size()-1-count);%0A            while(isSorted) %7B%0A                count++;%0A                if(list.size()-1-count==-1) %7B%0A                    break;%0A                %7D%0A                isSorted = isIncrease ? list.get(list.size()-1-count+1) %3C= list.get(list.size()-1-count) : list.get(list.size()-1-count+1) %3E= list.get(list.size()-1-count);%0A            %7D%0A            return count;%0A        %7D%0A        public List%3CInteger%3E getNext() %7B%0A            int count = sortedCount();%0A            if(count==list.size()) %7B%0A                return null;%0A            %7D else %7B%0A                swap(list.size()-1-count, swapIndex(list.size()-1-count));%0A                if(count!=1) %7B%0A                    reverse(list.size()-count, list.size()-1);%0A                %7D%0A            %7D%0A            return getCurrent();%0A        %7D%0A        public void swap(int aIndex, int bIndex) %7B%0A            int temp = list.get(aIndex);%0A            list.set(aIndex, list.get(bIndex));%0A            list.set(bIndex, temp);%0A        %7D%0A        public void reverse(int aIndex, int bIndex) %7B%0A            int mid = (bIndex - aIndex + 1) / 2;%0A            for(int diff=0 ; diff%3Cmid ; diff++) %7B%0A                swap(aIndex + diff , bIndex - diff);%0A            %7D%0A        %7D%0A        public List%3CInteger%3E getCurrent() %7B%0A            return list;%0A        %7D%0A    %7D%0A%7D%0A

Add Helper.Permutation