public
Created

Function to return whether or not one 'design' array 'fits' into another 'max'

  • Download Gist
array_fits_into_another.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// Currently incomplete implementation!
private Boolean designFits(int[] max, int[] design) {
 
Boolean designFits = true;
 
Arrays.sort(max);
Arrays.sort(design);
int passCount = 0;
 
if(design.length <= max.length) {
for(int i = 0; i < max.length; i++) {
for(int j = 0; j < design.length; j++) {
if(max[i] <= design[j]) {
passCount++;
}
}
}
if(passCount == 0 || passCount > max.length) {
designFits = false;
}
} else {
designFits = false;
}
 
return designFits;
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.