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的更多相关文章

  1. 【LeetCode】849. Maximize Distance to Closest Person 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 849. Maximize Distance to Closest Person ——weekly contest 87

    849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-clo ...

  3. [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 ...

  4. 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 ...

  5. [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 ...

  6. 【Leetcode_easy】821. Shortest Distance to a Character

    problem 821. Shortest Distance to a Character solution1: class Solution { public: vector<int> ...

  7. 【Leetcode_easy】783. Minimum Distance Between BST Nodes

    problem 783. Minimum Distance Between BST Nodes 参考 1. Leetcode_easy_783. Minimum Distance Between BS ...

  8. 849. Maximize Distance to Closest Person

    class Solution { public: int maxDistToClosest(vector<int>& seats) { ; ; for(int i:seats) / ...

  9. 【题解】UVA10140 [Prime Distance]

    [题解]UVA10140 Prime Distance 哈哈哈哈\(miller-rabbin\)水过去了哈哈哈 还能怎么办呢?\(miller-rabbin\)直接搞.枚举即可,还跑得飞快. 当然此 ...

随机推荐

  1. mage Ansible学习2 Playbook

    一.上集回顾 1.运维: 手动 --> 标准化 --> 工具化 --> 自动化 --> 智能化 2.工具化 OS Install:PXE ,Cobbler:Virutaliza ...

  2. 2017.10.6 国庆清北 D6T1 排序

    题目描述 小Z 有一个数字序列a1; a2; .... ; an,长度为n,小Z 只有一个操作:选 定p(1<p<n),然后把ap 从序列中拿出,然后再插⼊到序列中任意位置. 比如a 序列 ...

  3. java https

    1. 异常突现 在这普通的一天,我写普通的代码,却突然收到不普通的报警 javax.net.ssl.SSLHandshakeException: server certificate change i ...

  4. 《挑战30天C++入门极限》C++运算符重载函数基础及其值返回状态

        C++运算符重载函数基础及其值返回状态 运算符重载是C++的重要组成部分,它可以让程序更加的简单易懂,简单的运算符使用可以使复杂函数的理解更直观. 对于普通对象来说我们很自然的会频繁使用算数运 ...

  5. LayuiAdmin 单页版关闭当前页面tab的方式-图文

    需要关闭的时候 调用 parent.layui.admin.events.closeThisTabs() 即可执行当前页面的关闭 $.post("/index.php/WebAdmin/Wx ...

  6. hive 属性随笔记录

    set hive.mapred.mode=strict; //设置hive执行模式,默认为nonstrict(非严格模式),这里设置为严格模式 set hiveconf:hive.cli.print. ...

  7. 三层设备-SHRP详解

    步骤:3-sw1enconf tvlan databasevtp domain s2t117vtp servervlan 10vlan 20vlan 30vlan 40exitint r f0/7 - ...

  8. Java通过JDBC连接MySQL数据库(一)

    JDBC JAVA Database Connectivity java 数据库连接 为什么会出现JDBC SUN公司提供的一种数据库访问规则.规范, 由于数据库种类较多,并且java语言使用比较广泛 ...

  9. 【论文阅读】DCAN: Deep Contour-Aware Networks for Accurate Gland Segmentation

    DCAN: Deep Contour-Aware Networks for Accurate Gland Segmentation 作者:Hao Chen Xiaojuan Qi Lequan Yu ...

  10. longitudinal models | 纵向研究 | mixed model

    A longitudinal study refers to an investigation where participant outcomes and possibly treatments o ...