2 Star 0 Fork 0

xinanXu/myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LC849.cpp 746 Bytes
一键复制 编辑 原始数据 按行查看 历史
xinanXu 提交于 2023-08-24 20:42 . 849. 到最近的人的最大距离
class Solution {
public:
int maxDistToClosest(vector<int>& seats) {
int seat = 0, len = seats.size();
if (seats[0] == 0) {
int i = 0;
while (!seats[i])
i++, seat++;
}
if (!seats[len-1]) {
int tempseat = len - 1;
while (!seats[tempseat])
tempseat--;
tempseat = len - tempseat - 1;
seat = tempseat > seat ? tempseat : seat;
}
int temp = 0;
for (int i = 0; i < len; i++) {
if (seats[i]) {
seat = int((temp + 1) / 2) > seat ? int((temp + 1) / 2) : seat;
temp = 0;
}
else temp++;
}
return seat;
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/DearAtri/myleetcode.git
git@gitee.com:DearAtri/myleetcode.git
DearAtri
myleetcode
myleetcode
master

搜索帮助