849. Maximize Distance to Closest Person
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的更多相关文章
- 【Leetcode_easy】849. Maximize Distance to Closest Person
problem 849. Maximize Distance to Closest Person solution1: class Solution { public: int maxDistToCl ...
- 849. Maximize Distance to Closest Person ——weekly contest 87
849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-clo ...
- [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 ...
- 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 ...
- [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 ...
- 【LeetCode】849. Maximize Distance to Closest Person 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [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 ...
- [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 ...
- C#LeetCode刷题之#849-到最近的人的最大距离(Maximize Distance to Closest Person)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3754 访问. 在一排座位( seats)中,1 代表有人坐在座位 ...
随机推荐
- 22. Generate Parentheses (backTracking)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- 【资料整理】c#基础
.net基础:.net与C# .net是一个平台 c#是一门语言 .net的用途a.桌面应用程序 b.网站应用程序 c.专业游戏开发(XBOX360) d.嵌入式设备软件开发 e.智能手机APP开发 ...
- javascript简单的滑动效果
利用setInterval实现简单的滑动效果 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- [剑指Offer]24-反转链表
题目链接 https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=13&tqId=11168&t ...
- xcode 更新svn/Git后发现模拟器显示No Scheme问题
这个是由于XXX..xcodeproj包中xcuserdata文件夹中user.xcuserdatad文件夹名字的问题...user.xcuserdatad文件夹的名字,不是当前用户的名字,就会显示n ...
- 快速将磁盘的MBR分区方式改成GPT分区方式
1.按Shift + F10打开命令提示符. 2.diskpart 3.list disk(列出所有磁盘) 4.select disk 0(选择磁盘) 5.clean(格式化所选的磁盘) 7.conv ...
- 关于MYSQL字符集问题(一)
MySQL的字符集支持(Character Set Support)有两个方面: 字符集(Character set)和排序方式(Collation). 对于字符集的支持细化到四个层次: 服务器(se ...
- 自动发现项目中的所有URL
我的rbac组件,是想用到任何一个,项目中的. so 问题来了. - 问题: 拿到一个项目. 怎样获取到,当前项目中, 所有的URL 以及 每个URL的别名name, 还有是有 namespace 命 ...
- 在pom.xml中引入jar包坐标的依赖范围
A依赖B,需要在A的pom.xml文件中添加B的坐标,添加坐标时需要指定依赖范围,依赖范围包括: compile:编译范围,指A在编译时依赖B,此范围为默认依赖范围.编译范围的依赖会用在编译.测试.运 ...
- mysql 添加外键
create table class( cid tinyint unsigned primary key auto_increment, caption varchar(15) not null)en ...