private void permuteImp(ArrayList<ArrayList<Integer>> res, ArrayList<Integer> tmp, int[] num, boolean[] visited) {
        //if all checked, return
        if (tmp.size() == num.length) {
            res.add(new ArrayList<Integer>(tmp));
            return;
        }
        for (int i = 0; i < num.length; i++) {
            if (!visited[i]) {
                tmp.add(num[i]);
                visited[i] = true;
                //will recall the function, and the loop will jump the visited one
                permuteImp(res, tmp, num, visited);
                visited[i] = false;
                //after pass the list to the recall function, remove the add up element. in order to continue the loop to add next element.
                //backtracking
                tmp.remove(tmp.size() - 1);
                //if the ducplicate, jump that element
                while (i + 1 < num.length && num[i + 1] == num[i]) {
                    i++;
                }
            }
        }
    }