In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the closes…
In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the closes…
In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the closes…
849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-closest-person/description/ 思路:pre[i]存放i之前离最近的1的距离.post记录之后的. res = max(min(pre[i],[post[i])) 注意点:初始nst需要设计极大或极小值. 1 int maxDistToClosest(vector<int>&am…
problem 849. Maximize Distance to Closest Person solution1: class Solution { public: int maxDistToClosest(vector<int>& seats) { , n = seats.size(); vector<int> pos; ; i<n; ++i) { ) pos.push_back(i); } ; i<pos.size(); ++i) { ) res = m…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/maximize-distance-to-closest-person/description/ 题目描述 In a row of seats, 1 represents a person sitting in that seat, and 0 represents that…
Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Example 1: Input: S = "loveleetcode", C = 'e' Output: [3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0] Note: S string leng…
class Solution { public: int maxDistToClosest(vector<int>& seats) { ; ; for(int i:seats) //count the max length of continuous 0 { ) count++; else { maxseat=max(maxseat,count); count=; } } maxseat=(maxseat+)/; count=; ,j=seats.size()-; ) //count…
In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty.  There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the close…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3754 访问. 在一排座位( seats)中,1 代表有人坐在座位上,0 代表座位上是空的. 至少有一个空座位,且至少有一人坐在座位上. 亚历克斯希望坐在一个能够使他与离他最近的人之间的距离达到最大化的座位上. 返回他到离他最近的人的最大距离. 输入:[1,0,0,0,1,0,1] 输出:2 解释:如果亚历克斯坐在第二个空位(seats[2])上,他到离他最近的人…