class Solution
{
public:
int maxDistToClosest(vector<int>& seats)
{
int count=;
int maxseat=;
for(int i:seats) //count the max length of continuous 0
{
if(i==)
count++;
else
{
maxseat=max(maxseat,count);
count=;
}
}
maxseat=(maxseat+)/;
count=;
int i=,j=seats.size()-;
while(seats[i++]==) //count the max length of continuous 0 in the front
count++;
maxseat=max(count,maxseat);
count=;
while(seats[j--]==) //count the max length of continuous 0 in the last
count++;
maxseat=max(maxseat,count);
return maxseat;
}
};

此题不难,问题不大

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

  1. 【Leetcode_easy】849. Maximize Distance to Closest Person

    problem 849. Maximize Distance to Closest Person solution1: class Solution { public: int maxDistToCl ...

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

    849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-clo ...

  3. [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 emp ...

  4. leetcode 849. Maximize Distance to Closest Person

    In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...

  5. [LeetCode] 849. Maximize Distance to Closest Person 最大化最近人的距离

    In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...

  6. 【LeetCode】849. Maximize Distance to Closest Person 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  7. [LeetCode] Maximize Distance to Closest Person 离最近的人的最大距离

    In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...

  8. [Swift]LeetCode849. 到最近的人的最大距离 | Maximize Distance to Closest Person

    In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...

  9. C#LeetCode刷题之#849-到最近的人的最大距离(Maximize Distance to Closest Person)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3754 访问. 在一排座位( seats)中,1 代表有人坐在座位 ...

随机推荐

  1. Shell教程 之echo命令

    1.显示普通字符串 这里的双引号完全可以省略,以下命令效果一致: echo "传递参数实例!" echo 传递参数实例! 2.显示转义字符 echo "\"传递 ...

  2. Beginning C# Programming with Unity

    Welcome to the wonderful world of programming! In this book you’ll learn the basics of programming u ...

  3. windows下忘记mysql超级管理员root密码的解决办法(也适用于wamp)

    1.停止mysql服务. 2,在CMD命令行窗口,进入MYSQL安装目录 比如 d:mysql20080505in 3,进入mysql安全模式,即当mysql起来后,不用输入密码就能进入数据库.命令为 ...

  4. Centos 7.0 Firewall-cmd 使用方式

    开启端口命令 输入firewall-cmd --query-port=6379/tcp,如果返回结果为no,那么证明6379端口确实没有开启.输入firewall-cmd --add-port=637 ...

  5. c#devexpress GridContorl添加进度条

    demo 的实现图 下边是步骤和代码 1定义 时钟事件,定时的增加进度条的增量. 2:  添加进度条 3;定义字段属性 using System; using System.Collections.G ...

  6. vs 调试 IE显示“无法显示该网页

    在用VS2010调试网站的时候,突然页面不能正常显示了,IE显示“无法显示该网页”.症状一: IE地址栏里面显示的端口号和桌面任务栏右下角“ASP.NET Development Server”的端口 ...

  7. 简单选择排序(js版)

    简单选择排序 基本思想:通过n-i次关键字间的比较,从n-i+1个记录中选出关键字最小的记录,并和第i个记录交换.(废话不多说,先看代码). function SelectSort(arr){ var ...

  8. 自己动手开启QUIC(转载)

    源:https://www.bennythink.com/quic.html#title-0 今天在推上偶然发现 Google 在自己的服务器上启用了 QUIC,QUIC 这东西嘛(发音同 quick ...

  9. poj_1979(dfs)

    Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either re ...

  10. 怎么隐藏服务器的IP地址?

    服务器一般很少会使用公网地址,直接放置在互联网上使用. 一般是设置成局域网的私网地址,并通过路由器的端口映射,发布在互联网:内部的NAT转换,相当于隐藏了路由器,外网访问并不知道具体服务器的IP地址. ...