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 代表有人坐在座位 ...
随机推荐
- pandas_1
大熊猫10分钟 这是对熊猫的简短介绍,主要面向新用户.您可以在Cookbook中看到更复杂的食谱. 通常,我们导入如下: In [1]: import numpy as np In [2]: impo ...
- hdu 5154 拓扑排序
例题:hdu 5154 链接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思是第一行先给出n和m表示有n件事,m个关系,接下来输入m行,每行有 ...
- 1. Two Sum (快速排序;有序数组的查找: 两个指针; 哈希表)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- c++ sizeof,strlen, length
#include <map>#include <iostream>#include <algorithm>#include <functional>#i ...
- C++旅馆问题。
有总钱数 有每房每天住需要多少钱 问最少可以住几天 最后输入的是钱数.前边输入没个住所每天多少钱 例如: 1001 1002 1003 1004 1000 -1 100 500 600 最少一天,最多 ...
- 项目总结07:JS图片的上传预览和表单提交(FileReader()方法)
JS图片的上传预览和表单提交(FileReader()方法) 一开始没有搞明白下面这块代码的,今天有时间简单整理下 核心点:FileReader()方法 以下是代码(以JSP文件为例) <!DO ...
- Redis能干啥?细看11种Web应用场景[转]
下面列出11种Web应用场景,在这些场景下可以充分的利用Redis的特性,大大提高效率. 1.在主页中显示最新的项目列表. Redis使用的是常驻内存的缓存,速度非常快.LPUSH用来插入一个内容ID ...
- LINUX SSH修改默认22/添加端口
通常ssh远程登录的默认端口是22,但是因为端口22属于高危端口,因此很多时候作为服务器会被关掉,不过这个端口一般是可以更改或者添加的,这样除了22端口,也可以通过别的端口进行访问. 1.首先修改配置 ...
- Spring Boot 学习笔记1——初体验之3分钟启动你的Web应用[z]
前言 早在去年就简单的使用了一下Spring Boot,当时就被其便捷的功能所震惊.但是那是也没有深入的研究,随着其在业界被应用的越来越广泛,因此决定好好地深入学习一下,将自己的学习心得在此记录,本文 ...
- Oracle_高级功能(5) 用户、角色、权限
一.用户(模式)1.定义用户:对数据库的访问,需要以适当用户身份通过验证,并具有相关权限来完成一系列动作模式(schema):是某个用户所拥有的对象的集合.具有创建对象权限并创建了对象的用户称为拥有某 ...