class Solution {public: int maxDistToClosest(vector & seats) { int first = 0, last = seats.size() - 1; while (seats[first] == 0) first++; while (seats[last] == 0) last--; int md = 0, d = 0; for (int i = first + 1; i <= last; i++) { if (seats[i] == 0) d++; else { md = max(md, d); d = 0; } } return max(max(first, (int)seats.size() - last - 1), (md + 1) / 2); }};