q384_打乱数组

package 数组操作.q384_打乱数组;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
 * 洗牌算法 o(n)
 */
public class Solution {
    private int[] array;
    private int[] original;
    private Random rand = new Random();
    private List<Integer> getArrayCopy() {
        List<Integer> asList = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            asList.add(array[i]);
        }
        return asList;
    }
    public Solution(int[] nums) {
        array = nums;
        original = nums.clone();
    }
    public int[] reset() {
        array = original;
        original = original.clone();
        return array;
    }
    public int[] shuffle() {
        List<Integer> aux = getArrayCopy();
        for (int i = 0; i < array.length; i++) {
            int removeIdx = rand.nextInt(aux.size());
            array[i] = aux.get(removeIdx);
            aux.remove(removeIdx);
        }
        return array;
    }
}