problem

475. Heaters

solution1:

class Solution {
public:
int findRadius(vector<int>& houses, vector<int>& heaters){
int ans = , cur = , j = ;
sort(houses.begin(), houses.end());
sort(heaters.begin(), heaters.end());
for(int i=; i<houses.size(); i++)
{
cur = houses[i];
while(j<heaters.size()- && abs(heaters[j+]-cur)<=abs(heaters[j]-cur))
{
j++;
}
ans = max(ans, abs(heaters[j]-cur));
}
return ans; }
};

博主的理解就是计算每个house对应的能够cover到的最小值,注意两个数组有先进行排序哦,然后cover每个house的最小值中的最大值即为所求解的能够cover每个house的最小值。

参考

1. Leetcode_475. Heaters;

2. GrandYang;

【leetcode】475. Heaters的更多相关文章

  1. 【LeetCode】475. Heaters 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...

  2. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  3. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  4. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  5. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  6. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  7. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

  8. 【leetcode】893. Groups of Special-Equivalent Strings

    Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...

  9. 【leetcode】657. Robot Return to Origin

    Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...

随机推荐

  1. 微信小程序页面跳转导航wx.navigateTo和wx.redirectTo

    }) wx.redirectTo(OBJECT) 关闭当前页面,跳转到应用内的某个页面. 还是用上面的三张图示作为例子,当使用wx.redirctTo接口跳转页面时,原来的页面将被删除掉,当然,这是小 ...

  2. PCA算法数学原理及实现

    数学原理参考:https://blog.csdn.net/aiaiai010101/article/details/72744713 实现过程参考:https://www.cnblogs.com/ec ...

  3. dubbo服务暴露

    想熟悉dubbo源码,首先要知道dubbo extensionLoader,而dubbo的这种扩展机制,是根据java spi衍生而来. 这是基础,但是我放在后面说明. 一:dubbo demo pr ...

  4. FTP软件FileZilla 3.38.1下载

    FTP软件FileZilla 3.38.1下载 filezilla软件简介 FileZilla是一个免费开源的FTP软件,分为客户端版本和服务器版本,具备所有的FTP软件功能,具备极好的可控性及条理性 ...

  5. ubuntu安装smartGit

    1.首先安装jdk:(http://www.cnblogs.com/xiaochou/p/install_mint.html 评论区) 2.下载和安装smartGit: http://www.synt ...

  6. org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z和NewProxyPreparedStatement.isClosed()

    原文转:https://blog.csdn.net/qq_37909508/article/details/83028536 报错: NewProxyPreparedStatement.isClose ...

  7. centos7搭建vsftpd并启用虚拟用户

    虚拟用户的特点是只能访问服务器为其提供的FTP服务,不能访问系统的其它资源,所以,如果想让用户对FTP服务器站内具有写权限,但又不允许访问系统其他资源,可以使用虚拟用户来提高系统的安全性. 在vsft ...

  8. datatable处理gridview筛选后的值

    DataTable dt = (DataTable)gridView1.GridControl.DataSource; DataRow[] drr = dt.Select(gridView1.RowF ...

  9. PC端车牌识别朱凯茵从事图像识别算法、OCR算法

    大家好,我是从事图像识别的pc端车牌识别朱凯茵,多多交流OCR算法,不限于车牌识别等,技术需要突破,你我成就梦想.

  10. poj1002总结

    1.之前一直是runtime error,没有找出具体原因,把冒牌排序改成了合并排序,当输入是100000行时,从大约10s变到1s内 2.感觉是atoi指针导致的,当判断atoi的入参不为NULL时 ...