public void permutations(int[] num){
        if(list.size() == length){
            result.add(new ArrayList<Integer>(list));
            return;
        }
        for(int i = 0; i< length;i++){
            if(flag[i])
                continue;
            if(i > 0 && num[i] == num[i-1] && !flag[i-1])
                continue;
            flag[i] = true;
            list.add(num[i]);
            permutations(num);
            //roll back
            flag[i] = false;
            list.remove(list.size()-1);
        }
    }