详见:https://leetcode.com/problems/heaters/description/

C++:

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

参考:http://www.cnblogs.com/grandyang/p/6181626.html

475 Heaters 加热器的更多相关文章

  1. 【leetcode】475. Heaters

    problem 475. Heaters solution1: class Solution { public: int findRadius(vector<int>& house ...

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

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

  3. [LeetCode] Heaters 加热器

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  4. [Leetcode] Binary search -- 475. Heaters

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  5. 475. Heaters

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  6. 475. Heaters (start binary search, appplication for binary search)

    Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...

  7. 475. Heaters 加热范围

    [抄题]: Winter is coming! Your first job during the contest is to design a standard heater with fixed ...

  8. LeetCode_475. Heaters

    475. Heaters Easy Winter is coming! Your first job during the contest is to design a standard heater ...

  9. 【LeetCode】二分

    [475] Heaters [Easy] 给你一排房子,一排加热器.找到能warm所有房子的最小加热器半径. 思路就是对于每个房子,找离它最近的左右两台heater, 分别求距离.温暖这个房子的hea ...

随机推荐

  1. JAVA学习第十九课(java程序的异常处理 (二))

    异常处理的捕捉形式: 这是能够对异常进行针对性处理的方式 六.try.catch的理解 详细格式: try { //须要被检測异常的代码 } catch(异常类 变量)//改变量用于接受发生异常的对象 ...

  2. sanic官方文档解析之ssl,debug mode模式和test(测试)

    1,ssl 示例: 可选择的SSLContent from sanic import Sanic import ssl context = ssl.create_default_context(pur ...

  3. Mysql性能优化笔记

    一,索引 1.Innodb索引使用的是B+树 2.尽量简化where条件,比如不要出现 where id + 3 = 5,这无法使用索引 3.索引很大时,可以冗余一列来模拟哈希索引 4.小的表不需要使 ...

  4. SSM整理笔记1——SSM网站初步功能设计

    前言 因为公司里一直用Hibernate,但是现在Mybatis是趋势,所以搭建一个Mybatis的网站框架,目的是:1摸清其功能特点,2为以后的项目增加框架选择(以前只用hibernate或者Spr ...

  5. MySQL table

    -- 使用数据库hr use hr; -- 在数据库中创建表-- ------------------------------------JOBS表-------------------------- ...

  6. INFO: Ignoring response <403 https://movie.douban.com/top250>: HTTP status code is not handled or not allowed

    爬取豆瓣电影top250,出现以下报错: 2018-08-11 22:02:16 [scrapy.core.engine] INFO: Spider opened 2018-08-11 22:02:1 ...

  7. (转)Vim十大必备插件

    原文地址:http://www.open-open.com/lib/view/open1414227253419.html Vim十大必备插件 Taglist taglist是一个用于显示定位程序中各 ...

  8. [Selenium] Selenium common Actions Examples

    1.sendKeys() 在文本框中输入字符串 WebElement searchBox = driver.findElement(By.name("q")); searchBox ...

  9. 【HDU 2089】 不要62

    [题目链接] 点击打开链接 [算法] 数位DP 和上一题 : HDU3555很像 [代码] #include<bits/stdc++.h> using namespace std; #de ...

  10. Design with the User in Mind--从用户角度进行设计

    Back to Human Interface Design Design with the User in Mind 从用户角度进行设计 The success of a Mac app depen ...