We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Flatland Space Stations
Flatland Space Stations
Sort by
recency
|
948 Discussions
|
Please Login in order to post a comment
JAVA
static int flatlandSpaceStations(int n, int[] c) {
js my solution... if (n == c.length) return 0;
const lengthC = c.length - 1;
c.sort((a, b) => a - b); console.log(c);
let max = c[0]; for (let i = 0; i < lengthC; i++) { const tmp = Math.floor(c[i + 1] - (c[i + 1] + c[i]) / 2);
if (tmp > max) max = tmp; }
let lastOne = n - c[lengthC] - 1;
if (lastOne > max) max = lastOne;
console.log(max);
Python: My short solution…
I updated my code to make it more readable. Functional solutions aren't always difficult to read.