475 Heaters 加热器
2024-10-21 19:52:21
详见:https://leetcode.com/problems/heaters/description/
C++:
class Solution {
public:
int findRadius(vector<int>& houses, vector<int>& heaters)
{
int n = heaters.size(), j = 0, res = 0;
sort(houses.begin(), houses.end());
sort(heaters.begin(), heaters.end());
for (int i = 0; i < houses.size(); ++i)
{
int cur = houses[i];
while (j < n - 1 && abs(heaters[j + 1] - cur) <= abs(heaters[j] - cur))
{
++j;
}
res = max(res, abs(heaters[j] - cur));
}
return res;
}
};
参考:http://www.cnblogs.com/grandyang/p/6181626.html
最新文章
- The Honeynet ProjectThe Honeynet Project
- python 列表转为字典的两个小方法
- BP神经网络模型及算法推导
- 应用Oracle(用户创建和授权)
- jQuery中的插件的编写和使用
- 【IDE】IntelliJ IDEA (Mac) 运行速度优化(问题起因:debug模式突然变得巨慢)
- MYSQL事务及存储引擎对比
- Error400
- Docker 跨主机网络方案分析
- 浅谈前端中的mvvm与mvc
- Spring Boot 2.x (十):构建优雅的RESTful接口
- vue列表拖拽组件 vue-dragging
- 关于在CentOS上,绘图丢失部分中文字的问题
- ajax 跨域请求没有带上cookie 解决办法
- Docker的Mysql数据库:把数据存储在本地目录
- Js_Eval方法
- 跨域Ajax -- jsonp和cors
- python cx_oracle单个表中批量插入数据
- canvas createPattern()方法详解
- Python+selenium+pil+tesseract实现自动识别验证码