Advertisement
nikunjsoni

849

May 28th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxDistToClosest(vector<int> seats) {
  4.         int res = 0, n = seats.size(), last = -1;
  5.         for (int i = 0; i < n; ++i) {
  6.             if (seats[i] == 1) {
  7.                 res = last < 0 ? i : max(res, (i - last) / 2);
  8.                 last = i;
  9.             }
  10.         }
  11.         res = max(res, n - last - 1);
  12.         return res;
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement