public List<List<Integer>> permuteUnique(int[] num) {
        if(num == null || num.length ==0)
            return result;
        length = num.length;
        flag = new boolean[num.length];
        Arrays.sort(num);   // need sort first
        permutations(num);
        return result;
    }