Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created October 16, 2013 02:06
Show Gist options
  • Save cocodrips/7001559 to your computer and use it in GitHub Desktop.
Save cocodrips/7001559 to your computer and use it in GitHub Desktop.
SRM594 div2 500
import java.util.HashSet;
public class AstronomicalRecordsEasy {
public int minimalPlanets(int[] A, int[] B) {
int min = A.length + B.length - 1;
for (int a : A) {
for (int b : B) {
HashSet<Integer> set = new HashSet<Integer>();
for (int ai = 0; ai < A.length; ai++) {
set.add(A[ai] * b);
}
for (int bi = 0; bi < B.length; bi++) {
if (min <= set.size()) {
break;
}
set.add(B[bi] * a);
}
min = set.size();
}
}
return min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment