【发布时间】:2018-10-01 08:33:31
【问题描述】:
在下面的代码中,我试图得到一个Set 的circular primes 直到maxPlusOne。
Set<Integer> primes = getPrimes(maxPlusOne); //Returns a set of all primes up to maxPlusOne ont including it
Set<Integer> circularPrimes = new HashSet<>();
Iterator<Integer> it = primes.iterator();
while(it.hasNext()) {
Set<Integer> perms = getAllRotations(it.next()); //Returns all rotations of an integer 123 => {123, 231, 312}
if(primes.containsAll(perms)) {
circularPrimes.addAll(perms);
// Here I want to do something to the effect of removing all elements in perms from primes
}
}
现在在if 语句中,我想从primes 中删除perms 中的所有 元素。 This 答案显示了如何删除 iterator 指向的一个元素。甚至可以在一次迭代中从circularPrimes 中删除多个 元素吗?如果是,请帮忙。
【问题讨论】: