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 代表有人坐在座位 ...
随机推荐
- Jmeter 录制脚本(一)
第一种方法:使用Badboy来录制脚本 1. 启动Badboy, 工具栏上的红色圆形按钮是默认启动的,在地址栏直接输入被测试WEB项目的地址,然后点击右边的箭头. 2.录制完成后,点击工具栏上的黑色按 ...
- Python: PySide(Qt)异步获取网页源码
学习PyQt UI编程笔记.相对PyQt来说,PySide资料为少. 此篇记录异步获取代码后,同步显示于界面窗体中,涉及线程网步,此为知识点. 直录代码: # encoding: utf-8 from ...
- 浅析Java 数组-基础详解
什么是数组:数组对于每一门编程语言来说都是重要的数据结构之一,当然不同语言对数组的实现及处理也不尽相同. Java 数组:用来存储固定大小的同类型元素. 一 声明.创建,初始化Java 数组 写在前面 ...
- c++ 中map 的find 函数用法
Map中,find函数用来定位数据出现位置,当含有该数据,即查找成功时,返回数据所在未知的迭代器, 如果查找失败,则返回end()函数所在的迭代器,因此用是否等于end来判断是否查找成功. 程序示例: ...
- 模块math和cmath
python使用特殊命令import导入模块,再以module.function的方式使用模块 python标准库提供了一个专门用于处理复数的模块cmath,math处理数据 模块math常用的函数有 ...
- Java08-java语法基础(七)构造方法
Java08-java语法基础(七)构造方法 一.构造方法 1.什么是构造方法? 构造方法(类方法)是一个方法名和类名相容的特殊的成员方法. 2.构造方法的作用? 当使用new关键字创建一个对象时,为 ...
- android项目安装报错:INSTALL_FAILED_CONFLICTING_PROVIDER
这主要是由于调试的环境中已有一个同名的Provider存在. 解决方法是修改AndroidManifest.xml中的 <provider android:name="applockP ...
- (四)创建ROS程序包(就是软件包)
你的 ROS 程序包都放到下面这个目录里, 切换到这个目录: $ cd ~/catkin_ws/src 使用下面的命令: 创建一个 ROS 程序包 名字就叫:beginner_tutorials $ ...
- [z]根据awr报告查看最慢的sql语句
http://blog.itpub.net/12679300/viewspace-2125679/ 当系统运行了一段时间后,系统基本也趋于稳定了,SQL调优也变了DBA的一个主要的工作内容,很多时候都 ...
- day7 回顾
1,is == == 比较的是值. is 内存地址.对于int str 来说:存在小数据池的概念.为什么存在小数据池? 节省内存. int -5 ~ 256 str 全部字母,数字与单个字母想乘 数字 ...