public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) {
		ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
		if (num.length == 0)
			return result;

		if (num.length == 1) {
			ArrayList<Integer> onlyList = new ArrayList<Integer>();
			onlyList.add(new Integer(num[0]));
			result.add(onlyList);
			return result;
		}

		ArrayList<Integer> visited = new ArrayList<Integer>();
		for (int i = 0; i < num.length; i++) {
			Integer curNode = new Integer(num[i]);
			if (!visited.contains(curNode)) {
				// mark as visited
				visited.add(curNode);

				// create rest num's array
				int[] restNums = new int[num.length - 1];
				for (int j = 0, k = 0; j < num.length; j++) {
					if (j != i) {
						restNums[k] = num[j];
						k++;
					}
				}

				ArrayList<ArrayList<Integer>> restPermutes = permuteUnique(restNums);

				// merge the restPermutes with curNumber to create curNumber's
				// permute
				for (int m = 0; m < restPermutes.size(); m++) {
					ArrayList<Integer> curPermute = restPermutes.get(m);
					ArrayList<Integer> nodeCombined = new ArrayList<Integer>();
					nodeCombined.add(curNode);
					for (int n = 0; n < curPermute.size(); n++) {
						nodeCombined.add(new Integer(curPermute.get(n)));
					}
					result.add(nodeCombined);
				}
			}
		}

		return result;
	}