You are viewing a single comment's thread. Return to all comments →
static int flatlandSpaceStations(int numofcities, int[] spacestationcities) { int maxdistance = 0; for(int i=0; i<numofcities;i++) { int mindistance = Integer.MAX_VALUE; boolean hasstation=false; for(int j=0;j<spacestationcities.length; j++) { if(i==spacestationcities[j]) { hasstation = true; break; } if(i != spacestationcities[j]) { if(Math.abs(i-spacestationcities[j]) < mindistance) { mindistance = Math.abs(i-spacestationcities[j]); } } } if(mindistance > maxdistance && !hasstation) { maxdistance = mindistance; } } return maxdistance; }
Seems like cookies are disabled on this browser, please enable them to open this website
Flatland Space Stations
You are viewing a single comment's thread. Return to all comments →