1 class Solution 2 { 3 public: 4 int maxDistToClosest(vector<int>& seats) 5 { 6 int count=0; 7 int maxseat=0; 8 for(int i:seats) //count the max length of continuous 0 9 { 10 if(i==0) 11 count++; 12 else 13 { 14 maxseat=max(maxseat,count); 15 count=0; 16 } 17 } 18 maxseat=(maxseat+1)/2; 19 count=0; 20 int i=0,j=seats.size()-1; 21 while(seats[i++]==0) //count the max length of continuous 0 in the front 22 count++; 23 maxseat=max(count,maxseat); 24 count=0; 25 while(seats[j--]==0) //count the max length of continuous 0 in the last 26 count++; 27 maxseat=max(maxseat,count); 28 return maxseat; 29 } 30 };
此题不难,问题不大
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9193592.html
时间: 2024-10-09 05:35:33