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. .net core 获取本地ip及request请求端口

    1.获取ip和端口 string str = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + " ...

  2. (03) spring Boot 的配置

    1. spring boot 的核心配置 spring boot 项目建立之后,已经创建好了application.properties 配置文件 其实, 配置文件还支持*.yml 格式的: 2. 多 ...

  3. JavaScript instanceof 运算符

    instanceof运算符简介 在 JavaScript 中 判断一个变量的类型常常会用 typeof 运算符 判断一个实例是否属于某种类型会使用instanceof 与 typeof 方法不同的是, ...

  4. 索引优化原则及Oracle中索引总结

    索引建立原则 确定针对该表的操作是大量的查询操作还是大量的增删改操作. 尝试建立索引来帮助特定的查询.检查自己的sql语句,为那些频繁在where子句中出现的字段建立索引. where语句中不得不对查 ...

  5. Jeecg

    姓名:黄于霞          班级:软件151 1.第一步将Jeecg引包到javaEE中,如图下图所示: 2.第二步改jeecg_config.properties中的用户名和密码改成和数据库中一 ...

  6. test--1

    void(document.body.innerHTML.replace(/"return DeletePost\((\d+),([^"]+)\)"/g, functio ...

  7. c#实现数据库的备份

    在.NET开发后天管理系统的时候,数据库的备份功能是必须实现的一块,而在数据库备份方面一句sql语句就可以搞定了,那就是<Backup Database 数据库名To disk='路径\数据库备 ...

  8. SQL循环表里的数据

    select * into #t1 from Userinfodeclare @id varchar(2000);while (exists(select ProjectID from #t1))be ...

  9. C语言的#if #ifdef #ifndef

    #if #ifedf #ifndef   —般情况下,C语言源程序中的每一行代码.都要参加编译.但有时候出于对程序代码优化的考虑.希望只对其中一部分内容进行编译.此时就需要在程序中加上条件,让编译器只 ...

  10. 什么是 Message Queue

    Message Queue 是一种非同步的从一个服务到另一个服务的交流形式, 被用于无服务器架构和微服务架构中. Messages 被储存在一个队列中直到被处理了或被删除. 每个Messages只会被 ...