problem
849. Maximize Distance to Closest Person
solution1:
class Solution { public: int maxDistToClosest(vector<int>& seats) { int res = 0, n = seats.size(); vector<int> pos; for(int i=0; i<n; ++i) { if(seats[i] == 1) pos.push_back(i); } for(int i=0; i<pos.size(); ++i) { if(i==0) res = max(res, pos[i]); else res = max(res, (pos[i]-pos[i-1])/2); } if(!pos.empty()) res = max(res, n-1-pos.back()); return res; } };
参考
1. Leetcode_easy_849. Maximize Distance to Closest Person;
2. grandyang;
完