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 };

此题不难,问题不大

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

时间: 2024-10-09 05:35:33

849. Maximize Distance to Closest Person的相关文章

849. Maximize Distance to Closest Person ——weekly contest 87

849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-closest-person/description/ 思路:pre[i]存放i之前离最近的1的距离.post记录之后的. res = max(min(pre[i],[post[i])) 注意点:初始nst需要设计极大或极小值. 1 int maxDistToClosest(vector<int>&am

【Leetcode_easy】849. Maximize Distance to Closest Person

problem 849. Maximize Distance to Closest Person 参考 1. Leetcode_easy_849. Maximize Distance to Closest Person; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11214905.html

[LeetCode] 849. Maximize Distance to Closest Person_Easy tag: BFS

In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the closes

LeetCode算法题-Maximize Distance to Closest Person(Java实现)

这是悦乐书的第328次更新,第351篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第198题(顺位题号是849).在一排座位中,1表示一个人坐在该座位上,0表示座位是空的.在这些座位中,至少有一个空座位,至少有一个人坐着.Alex想坐在座位上,以便他和离他最近的人之间的距离最远.返回距离最近的人的最大距离.例如: 输入:[1,0,0,0,1,0,1] 输出:2 说明:如果Alex坐在第二个空座位(seats[2]),那么离最近的人距离为2.如果Alex坐在任何其他空

【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849

package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: IsOneBitCharacter * @Author: xiaof * @Description: TODO 717. 1-bit and 2-bit Characters * We have two special characters. The first charac

【LeetCode】数组

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica } [1]Two Sum [4]Median of Two Sorted Arrays [11]Container With Most Water [15]3Sum [16]3Sum Closest [18]4Sum [26]Remove Duplicates from Sorted Array [27]Remove Element [31]Next Permutatio

Unity控件ScrollView使用问题记录

Unity版本:5.6.2 控件Scroll View由4部分组成,如图: 1.含有Scroll Rect组件的根节点:Scroll View 2.含有Mask组件的节点:Viewport 3.所有内容的父节点Content,常含有布局控件 4.滚动条,包括横向和纵向 具体的节点细节使用可以参看官方文档:https://docs.unity3d.com/560/Documentation/Manual/script-ScrollRect.html 使用时遇到的问题记录: 1.显示区域怎么控制?节

FingerPrint Fuzzy Vault Matlab实践

本文实践了指纹识别生物特征识别研究论文A Fuzzy Vault Scheme的算法部分.原文请查看以下链接: Juels, A. & Sudan, M. Des Codes Crypt (2006) 38: 237. doi:10.1007/s10623-005-6343-z 准备知识: 1.有限域/伽罗华域(Galois Field,GF) 2.RS编码和纠错算法RS(Reed-Solomon)码 3.多项式构建和重构 4.模糊保险箱Fuzzy Vault 5.Talk is cheap,s

UNREAL ENGINE 4.12 正式发布!下载地址

UNREAL ENGINE 4.12 正式发布! 下载地址:https://www.unrealengine.com/ Alexander Paschall 在 June 1, 2016 |功能新闻社区 Share on Facebook Share on Twitter Share on Google+ Share on LinkedIn 此版本内含虚幻引擎 4 的数百个更新,以及 GitHub 虚幻引擎开发者社区提交的 106 项改良!特此对虚幻引擎 4.12 版本的贡献者们表达诚挚谢意: