码迷,mamicode.com
首页 > 其他好文 > 详细

849. Maximize Distance to Closest Person

时间:2018-06-17 20:50:52      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:return   lse   IV   pre   toc   color   distance   tor   int   

 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

标签:return   lse   IV   pre   toc   color   distance   tor   int   

原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9193592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!