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. js中Array数组基本方法

    总结:push() 添加元素到数组未尾, 返回数组长度 unshift() 添加元素到数组头部, 返回数组长度 pop() 删除数组未尾元素, 返回删除元素 shift() 删除数组头部元素, 返回删 ...

  2. 在vue中添加sass的配置的方法

    1.安装sass的依赖包 npm install --save-dev sass-loader //sass-loader依赖于 node-sass npm install --save-dev no ...

  3. mysql 执行sql流程

    客户端发送sql 语句后的堆栈 #0 0x0000000100370565 in do_command(THD*) at percona-server-Percona-Server-5.6.37-82 ...

  4. 接口压力测试--Jmeter

    1.Jmeter简介 JMeter就是一个测试工具,相比于LoadRunner等测试工具,此工具免费,且比较好用,但是前提当然是安装Java环境: JMeter可以做 (1)压力测试及性能测试: (2 ...

  5. asp.netmvc部署到linux(centos)

    介绍将asp.netmvc项目部署到centos系统. 开发工具:win10+vs2017+.NetFramework4.6.1+Vmware14+centos 1.安装Jexus 这里使用独立版(专 ...

  6. log日志文件

    单文件写 根据日志的等级是否写入,下面的一个例子就是等级为10,大于等于等级10的记录,小于的话就不记录,在创建之前先进行基本的日志格式配置 import logging logging.basicC ...

  7. CSS可见区域全局居中

    top:$(document).scrollTop() + ($(document).height() - $(document).scrollTop())/2,

  8. 【转载】Excel 三维地图入门

    三维地图入门(office 2016) https://support.office.com/zh-cn/article/%E4%B8%89%E7%BB%B4%E5%9C%B0%E5%9B%BE%E5 ...

  9. 分享:五个非常有用的WP插件

    一全老师(www.yiquanseo.com)认为非常有用的几款WP插件,用WordPress做站的可以看下,估计你很可能用得到! 第一款WooCommerce Page Builder: 这款插件是 ...

  10. 总结Jquery中获取自定义属性使用.attr()和.data()以及.prop()的区别

    一..attr()和.data()的区别: .attr()和.data()本质上属于DOM属性和Jquery对象属性的区别. 看一个例子: <!DOCTYPE html> <html ...