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. rpc概念及nfs的基本应用

    NFS:Network File System NFS监听在TCP/UDP:2049端口: nfs服务器: [root@localhost ~]#yum -y install [root@localh ...

  2. 基于JDK1.8版本的hashmap源码分析(一)

    今天看了下hashmap中的源码,下面列出一些自己的收获 开头,public class HashMap<K,V> extends AbstractMap<K,V>    im ...

  3. 前端页面的适配使用rem换算

    前端页面的适配使用rem换算 https://www.cnblogs.com/liangxuru/p/6970629.html 注:本文转载之处:https://www.cnblogs.com/ann ...

  4. pip安装问题

    一,安装pyecharts 出现问题的2个提示 failed to import pyecharts_snapshot   成功解决 第一个升级问题 you are using pip version ...

  5. 记录这段时间java编程的小知识点

    记录这段时间java编程的小知识点 eclipse项目导入中文乱码 eclipse左侧目录结构变动 eclipse代码段左右移动 按tal键,是整体右移. 按shift  table 同时按,是整体左 ...

  6. JDBCUtils——C3P0

    需要导入的包: mysql-connector-java-5.1.37-bin.jar c3p0-0.9.2-pre5.jar mchange-commons-java-0.2.3.jar 如果使用D ...

  7. [Leetcode 39]组合数的和Combination Sum

    [题目] Given a set of candidate numbers (candidates) (without duplicates) and a target number (target) ...

  8. 004dayPython学习输入并输出用户名和密码

    在python 2.7中,捕获用户输入用raw_input 一.捕获并打印用户名和密码 要求: 输入用户名和密码都可见 # -*- coding:utf-8 -*-userName = raw_inp ...

  9. 认识jQuery

    JQ的优势 轻量级. 强大的选择器 出色的DOM操作的封装 可靠的事件处理机制 完善的Ajax 不污染顶级变量 出色的浏览器兼容性 链式操作 隐式迭代 行为层与结构层分离 丰富的插件支持 完善的文档 ...

  10. 验证GridControl Gridview 单元格。

    一般的验证方法,使用单元格值改变事件.现在记录另一个事件实现验证. 场景:控制当某个单元格的值的长度不能超过10 直接看代码: private void gridViewFileContent_Val ...