475. Heaters Medium

@problem@discussion
#Array#Two Pointers#Binary Search#Sorting



1/**
2 * [475] Heaters
3 *
4 * Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.
5 * Every house can be warmed, as long as the house is within the heater's warm radius range. 
6 * Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses.
7 * Notice that all the heaters follow your radius standard, and the warm radius will the same.
8 *  
9 * Example 1:
10 * 
11 * Input: houses = [1,2,3], heaters = [2]
12 * Output: 1
13 * Explanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.
14 * 
15 * Example 2:
16 * 
17 * Input: houses = [1,2,3,4], heaters = [1,4]
18 * Output: 1
19 * Explanation: The two heater was placed in the position 1 and 4. We need to use radius 1 standard, then all the houses can be warmed.
20 * 
21 * Example 3:
22 * 
23 * Input: houses = [1,5], heaters = [2]
24 * Output: 3
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= houses.length, heaters.length <= 3 * 10^4
30 * 	1 <= houses[i], heaters[i] <= 10^9
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/heaters/
36// discuss: https://leetcode.com/problems/heaters/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn find_radius(houses: Vec<i32>, heaters: Vec<i32>) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_475() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.