【Leetcode_easy】849. Maximize Distance to Closest Person
2024-10-06 06:09:53
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;
完
最新文章
- TODO:Go语言goroutine和channel使用
- Ehcache 缓存使用
- Sublime Text插件:HTML-CSS-JS Prettify
- 安装GO语言环境之安装Visual Studio Code插件
- NGUI:HUD Text(头顶伤害漂浮文字)
- 增强学习————K-摇臂赌博机
- uva 10271
- 第一章:在IDEA里搭建基于Forge的Minecraft mod开发环境
- TF卡速度测试对比 Class数越高速度越快
- Android 窗口全屏
- Maven之(六)setting.xml配置文件详解
- yaml的用法
- jenkins持续集成原理
- bat脚本,备份数据库并压缩
- Tomcat 启动图解
- TensorFlow 安装 Ubuntu14.04
- Python Socket套接字
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)
- 代码Rework中的反思
- AC日记——Count on a tree bzoj 2588
热门文章
- Hi,this is May.
- Oracle 解决无法生成Snapshot问题
- 鼠标经过盒子出现边框(伪元素,定位,css3盒子模型)
- test命令用法。功能:检查文件和比较值
- SVN版本回滚实战
- [WEB安全]SSRF中URL的伪协议
- OSG学习笔记0——解决OSG读obj模型问题[转]
- U盘量产过程PS2251-07(PS2307) - F/W 01.05.10 [2014-05-23]
- zabbix ALL = NOPASSWD: ALL
- 网关 apache APISIX