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;

最新文章

  1. TODO:Go语言goroutine和channel使用
  2. Ehcache 缓存使用
  3. Sublime Text插件:HTML-CSS-JS Prettify
  4. 安装GO语言环境之安装Visual Studio Code插件
  5. NGUI:HUD Text(头顶伤害漂浮文字)
  6. 增强学习————K-摇臂赌博机
  7. uva 10271
  8. 第一章:在IDEA里搭建基于Forge的Minecraft mod开发环境
  9. TF卡速度测试对比 Class数越高速度越快
  10. Android 窗口全屏
  11. Maven之(六)setting.xml配置文件详解
  12. yaml的用法
  13. jenkins持续集成原理
  14. bat脚本,备份数据库并压缩
  15. Tomcat 启动图解
  16. TensorFlow 安装 Ubuntu14.04
  17. Python Socket套接字
  18. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)
  19. 代码Rework中的反思
  20. AC日记——Count on a tree bzoj 2588

热门文章

  1. Hi,this is May.
  2. Oracle 解决无法生成Snapshot问题
  3. 鼠标经过盒子出现边框(伪元素,定位,css3盒子模型)
  4. test命令用法。功能:检查文件和比较值
  5. SVN版本回滚实战
  6. [WEB安全]SSRF中URL的伪协议
  7. OSG学习笔记0——解决OSG读obj模型问题[转]
  8. U盘量产过程PS2251-07(PS2307) - F/W 01.05.10 [2014-05-23]
  9. zabbix ALL = NOPASSWD: ALL
  10. 网关 apache APISIX