1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class Solution { public int maxDistToClosest(int[] seats) { int last = -1, d = 0, n = seats.length, ans = 1; for (int i = 0; i < n; ++i) { if (seats[i] == 1) { if (last == -1) ans = Math.max(ans, i); else ans = Math.max(ans, (i - last) / 2); last = i; } } ans = Math.max(ans, n - last - 1); return ans; } }
|