当前位置:网站首页>[Title brushing] heater
[Title brushing] heater
2022-06-30 13:31:00 【m0_ sixty million six hundred and thirty-one thousand three hun】
One 、 subject
OJ link
Winter has come . Your task is to design a heater with fixed heating radius to heat all houses .
Every house within the heating radius of the heater can be heated .
Now? , Give the house on a horizontal line houses And heater heaters The location of , Please find and return the minimum heating radius that can cover all houses .
explain : All heaters follow your radius standard , The radius of the heating is the same .
source : Power button (LeetCode) link :https://leetcode.cn/problems/heaters
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Two 、 Answer key
2.1 Ideas


2.2 Source code
public static int findRadius(int[] houses, int[] heaters) {
Arrays.sort(houses);
Arrays.sort(heaters);
int ans=0;
for (int i = 0,j=0; i < houses.length ; i++) {
while (!best(houses,heaters,i,j)){
j++;
}
ans=Math.max(ans,Math.abs(heaters[j]-houses[i]));
}
return ans;
}
public static boolean best(int[] houses,int[] heaters,int i,int j){
return j==heaters.length-1||(Math.abs(heaters[j]-houses[i])<Math.abs(heaters[j+1]-houses[i]));
}

边栏推荐
- 【系统分析师之路】第五章 复盘软件工程(软件过程改进)
- Basic syntax of unity script (3) - accessing game object components
- Mqtt ROS simulates publishing a custom message type
- 优思学院:六西格玛不只是统计!
- Unity Animator 参数
- Multi terminal collaboration of Huawei accounts to create a better internet life
- ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accurately
- 目录相关命令
- In line with the trend of media integration, Zhongke Wenge and Meishe jointly create digital intelligence media publicity
- An interesting thing happened in the project
猜你喜欢

JS converts an array to a two-dimensional array based on the same value

Goods and services - platform properties

微信小程序报错:TypeError: Cannot read property ‘setData‘ of undefined

RK356x U-Boot研究所(命令篇)3.3 env相关命令的用法

【刷题篇】避免洪水泛滥

腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?

IDEA 2021.3 执行 golang 报错:RNING: undefined behavior version of Delve is too old for Go version 1.18

Resource realization applet opening traffic main tutorial

排查问题的方法论(适用于任何多方合作中产生的问题排查)

DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
随机推荐
Basic syntax of unity script (2) -record time in unity
逆向调试入门-PE中的VA与RVA换算04/07
损失函数:DIOU loss手写实现
How can I protect my private key?
How does MySQL merge columns?
ABAP工具箱 V1.0(附实现思路)
发生QQ大规模盗号事件,暴露出什么网络安全问题?
常用的ui组件
Basics of golang -- the difference between slicing and array
Golang Basics - string and int, Int64 inter conversion
【刷题篇】供暖器
60 divine vs Code plug-ins!!
资源变现小程序开通流量主教程
SQL programming problem, test case failed
Postman automatically generates curl code snippets
排查问题的方法论(适用于任何多方合作中产生的问题排查)
Write, append, read, and copy of golang files: examples of using bufio packages
[deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and "zero value"
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
数据库表为什么写不进数据了