【Leetcode_easy】849. Maximize Distance to Closest Person
problem
849. Maximize Distance to Closest Person
solution1:
class Solution {
public:
int maxDistToClosest(vector<int>& seats) {
int res = , n = seats.size();
vector<int> pos;
for(int i=; i<n; ++i)
{
if(seats[i] == ) pos.push_back(i);
}
for(int i=; i<pos.size(); ++i)
{
if(i==) res = max(res, pos[i]);
else res = max(res, (pos[i]-pos[i-])/);
}
if(!pos.empty()) res = max(res, n--pos.back());
return res;
}
};
参考
1. Leetcode_easy_849. Maximize Distance to Closest Person;
2. grandyang;
完
【Leetcode_easy】849. Maximize Distance to Closest Person的更多相关文章
- 【LeetCode】849. Maximize Distance to Closest Person 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 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_easy】821. Shortest Distance to a Character
problem 821. Shortest Distance to a Character solution1: class Solution { public: vector<int> ...
- 【Leetcode_easy】783. Minimum Distance Between BST Nodes
problem 783. Minimum Distance Between BST Nodes 参考 1. Leetcode_easy_783. Minimum Distance Between BS ...
- 849. Maximize Distance to Closest Person
class Solution { public: int maxDistToClosest(vector<int>& seats) { ; ; for(int i:seats) / ...
- 【题解】UVA10140 [Prime Distance]
[题解]UVA10140 Prime Distance 哈哈哈哈\(miller-rabbin\)水过去了哈哈哈 还能怎么办呢?\(miller-rabbin\)直接搞.枚举即可,还跑得飞快. 当然此 ...
随机推荐
- (转载) 搭建非域AlwaysOn win2016+SQL2016
非域搭建Alwayson只是省去搭建域控那一部分,其他大同小异 条件: 操作系统:windows server 2016 数据库:SQL Server 2016 SSMS版本:17.3 节点1:HDD ...
- DW-ODS
ODS (操作数据存储) 编辑 讨论 操作数据存储ODS(Operational Data Store)是数据仓库体系结构中的一个可选部分,也被称为贴源层.ODS具备数据仓库的部分特征和OLTP系统的 ...
- OSS使用
https://www.cnblogs.com/wumian1360/p/8486726.html https://help.aliyun.com/document_detail/52204.html ...
- 一个有趣的js隐式转换的问题
一个有趣的js隐式转换的问题 在chrome的控制台中打印一下表达式 [] + {} //结果为 [object object] 然后调整顺序打印 {} + [] //结果为 0 然后将两个表达式组合 ...
- stat函数
int lstat(const char *path,struct stat*buf) 当文件是一个符号链接时,lstat返回的是该符号链接本身的信息,而stat返回的是该链接指向的文件的信息. st ...
- segfault at 0 ip sp error 14
error 14从未见过.谁能帮我解答什么情况才会出现这个,而且怎么定位崩溃函数地址? 备忘: segfault at 引起故障的地址ip 指令的内存地址sp 堆栈指针地址, 及栈顶指针err is ...
- loadRunner目录分析<二>
loadRunner是用C语言进行编写的所以很多文件都是以.h文件结尾的 挑选一部分关键目录结构进行说明 1.analysis templates --分析模板,案例模板 2.bin --可执行程序, ...
- STP生成树算法
生成树算法第一:决定谁是“根网桥”对比各个网桥ID,先对比ID中的优先级,优先级相同的时候对比网桥MAC地址,对比依据是谁的值最小,谁是“根网桥” 第二:决定哪些是“根端口”窍门——每个非根网桥上都有 ...
- 深入浅出一致性Hash原理
转自:https://www.jianshu.com/p/e968c081f563 一.前言 在解决分布式系统中负载均衡的问题时候可以使用Hash算法让固定的一部分请求落到同一台服务器上,这样每台服务 ...
- Ubuntu -- unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=...)
#添加沙盒模式 chrome_options.add_argument("--no-sandbox")