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. 【Monkey】Monkey基础概念

    1.什么是Monkey? 发送伪随机用户事件的命令 2.Monkey在哪? 在手机系统里 3.什么是ADB? 4.MonkeyScript 一组可以被Monkey识别的命令集合,可以完成重复固定的操作 ...

  2. scrapy 入门爬取新闻

    为文本分类实验爬取数据集,要求一百万,分类>10类. 参考链接:http://litianyi.cc/technology/2015/12/01/text-classification-1/ 文 ...

  3. 在本地运行正常的静态网页放到tomcat中却显示异常的原因

    在本地写好了一个个人网站,本地直接用浏览器运行,很顺利,然而把网站放到Tomcat里面,却发现图片显示不出来,这就奇怪了. 后来发现,我的网站的Image文件夹用了大写“I”,而网页里面的路径用了小写 ...

  4. org.hibernate.ObjectNotFoundException: No row with the given identifier exists

    维护老系统时出现的问题,出现的原因我简述一下: table1与table2是关联表,T1中有T2的主键 "T1_id",当T1中的 "T2_id" 不为null ...

  5. Linux快捷键总结

    使用Linux很久了,现对经常用到的快捷键做一个总结: 最重要的一个当然是tab了 [root@localhost ~]# cd /etc/sys sysconfig/ sysctl.conf sys ...

  6. 从SQLServer转储数据到MySQL

    前一段时间,由于项目需要将数据库从SQLServer迁移到MySQL,在网上百度了很久,基本都是通过SQLyog实现的.其实使用平时常用的数据库管理软件Navicat Premium也能做到,并且操作 ...

  7. 关于visual studio的一些日常总结

    一.常用的VS快捷键 批量注释:ctrl + k ctrl + c 批量解除注释:ctrl + k ctrl + u 转到声明:ctrl + F12 查找:ctrl + F 添加断点:F9 逐过程调试 ...

  8. [Linux] Extend space of root disk in Linux7

    [root@node1 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 26G 17G 9.8G ...

  9. Oracle查询和过滤重复数据

    对数据库某些意外情况,引起的重复数据,如何处理呢? ----------------查重复: select * from satisfaction_survey s and s.project_no ...

  10. CSS多行文字超出隐藏加省略号

    overflow: hidden; text-overflow:ellipsis; white-space: nowrap; 限制行数 overflow: hidden; text-overflow: ...