详见: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

最新文章

  1. The Honeynet ProjectThe Honeynet Project
  2. python 列表转为字典的两个小方法
  3. BP神经网络模型及算法推导
  4. 应用Oracle(用户创建和授权)
  5. jQuery中的插件的编写和使用
  6. 【IDE】IntelliJ IDEA (Mac) 运行速度优化(问题起因:debug模式突然变得巨慢)
  7. MYSQL事务及存储引擎对比
  8. Error400
  9. Docker 跨主机网络方案分析
  10. 浅谈前端中的mvvm与mvc
  11. Spring Boot 2.x (十):构建优雅的RESTful接口
  12. vue列表拖拽组件 vue-dragging
  13. 关于在CentOS上,绘图丢失部分中文字的问题
  14. ajax 跨域请求没有带上cookie 解决办法
  15. Docker的Mysql数据库:把数据存储在本地目录
  16. Js_Eval方法
  17. 跨域Ajax -- jsonp和cors
  18. python cx_oracle单个表中批量插入数据
  19. canvas createPattern()方法详解
  20. Python+selenium+pil+tesseract实现自动识别验证码

热门文章

  1. HBase2.0新特性之In-Memory Compaction
  2. Java面试必会知识点
  3. Windows 7 繁体中文MSDN原版
  4. 织梦dedecms页面中增加二维码功能的实现方法
  5. Scanner、String(java基础知识十二)
  6. lovelygallery_popup(卡哇依相册)
  7. iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)
  8. oracle 转移表空间
  9. bzoj4566
  10. 【旧文章搬运】改PEB中的映像路径可以这样~