Java tutorial
//package com.java2s; /** * jcombinatorics: * Java Combinatorics Library * * Copyright (c) 2009 by Alistair A. Israel. * * This software is made available under the terms of the MIT License. * See LICENSE.txt. * * Created Aug 31, 2009 */ public class Main { /** * Iterate over the elements in the <code>subset</code> and set the first * elements to <code>-1</code> in the <code>multiset</code> which equals the * subset elements. Return a new reduced multiset <code>int[]</code> array * where the <code>-1</code> values are deleted. * * @param multiset * a multiset containing equals or greater than elements as the * subset. * @param subset * a subset with the elements which should be deleted. * @return */ public static int[] deleteSubset(int[] multiset, int[] subset) { int size = multiset.length; int[] setClone = new int[size];// multiset.clone(); System.arraycopy(multiset, 0, setClone, 0, size); int k = 0; for (int j = 0; j < subset.length; j++) { for (int i = k; i < setClone.length; i++) { if (subset[j] == setClone[i]) { setClone[i] = -1; size--; k = i + 1; break; } } } int[] result = new int[size]; k = 0; for (int i = 0; i < setClone.length; i++) { if (setClone[i] != -1) { result[k++] = setClone[i]; } } return result; } }