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. CentOS 下搭建Gitlab

    centos7安装部署gitlab服务器   我这里使用的是centos 7 64bit,我试过centos 6也是可以的! 1. 安装依赖软件 yum -y install policycoreut ...

  2. HDU-2054.A==B?(字符串简单处理)

    这道题......被我各种姿势搞死的... 本题大意:给出两个数A和B,判断A和B是否相等,对应输出YES or NO. 本题思路:本题我有两种思路,第一种是直接去除前导零和后导零然后稍加处理比较字符 ...

  3. Balanced Numbers (数位DP)

    Balanced Numbers https://vjudge.net/contest/287810#problem/K Balanced numbers have been used by math ...

  4. 第一个springMVC小程序

    1首先配置一个前端控制器,在web.xml文件中配置(dispatcherservlet) <!-- 前端控制器配置 --> <servlet> <servlet-nam ...

  5. maven 常用参数使用详解

    前言 作为java开发按人员,使用maven构建似乎成为了工作中平常的事情,但有时会遇到一些问题,感到困惑,于是我整理出来,方便其他同学更好的使用,以后会慢慢更新这个文章. 命令介绍 -DskipTe ...

  6. django的model操作整理

    单表操作 增加数据 auther_obj = {"auther_name":"崔皓然","auther_age":1} models.aut ...

  7. Flexible variants in STVARV

    DATA: lv_time TYPE TVARV_VAL, lv_tvarvc(25) . CONSTANTS lv_prefix(25) VALUE 'ZZXXS_'. CONCATENATE lv ...

  8. 关于MYSQL字符集问题(一)

    MySQL的字符集支持(Character Set Support)有两个方面: 字符集(Character set)和排序方式(Collation). 对于字符集的支持细化到四个层次: 服务器(se ...

  9. gearman中任务的优先级和返回状态

    gearman中任务的优先级和返回状态 一.任务的优先级 同步阻塞调用,等待返回结果 doLow:最低优先 doNomal:正常优先级 doHigh:最优先执行 异步派发任务,不等待返回结果,返回任务 ...

  10. Windows Server 2008 MetaFile设置占用内存限制

    最近遇到Windows Server 2008服务器内存持续飙升,48G内存用了99%,查看任务管理器的进程,也没发现具体哪个进程用的内存比较大? 于是,在网上找了了一个查看内存的工具RamMap,具 ...