作者: 负雪明烛 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…
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…
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…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/find-k-closest-elements/description/ 题目描述: Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also b…
题目要求 Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Note: S string length is in [1, 10000]. C is a single character, and guaranteed to be in string S. All letters…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 递归 迭代 日期 题目地址:https://leetcode.com/problems/binary-tree-inorder-traversal/ 题目描述 Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree…