849. Maximize Distance to Closest Person
Posted zhuangbijingdeboke
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了849. Maximize Distance to Closest Person相关的知识,希望对你有一定的参考价值。
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 };
此题不难,问题不大
以上是关于849. Maximize Distance to Closest Person的主要内容,如果未能解决你的问题,请参考以下文章
849. Maximize Distance to Closest Person ——weekly contest 87
849. Maximize Distance to Closest Person
[LeetCode] 849. Maximize Distance to Closest Person_Easy tag: BFS