草原上的牛群需要找到一个合适的地区,使得生育的数量达到最大。这些地区高度用整数数组 heights 表示,数组中的每个值表示对应地区的高度。在合适的地区,高度差足够小(小于或等于阈值 k),以便牛群容易迁徙和生育。您的任务是在这些高度范围内计算最大的地区范围,以使高度差不超过 k。
示例1
输入
[1, 5, 3, 10, 5, 4, 8],3
输出
2
说明
最大高度不超过3的,可以是[5,3]或者[5,4]
备注:
heights(2 k(0
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ public int findMaxRangeWithinThreshold (int[] heights, int k) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型vector * @param k int整型 * @return int整型 */ int findMaxRangeWithinThreshold(vector
& heights, int k) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param heights int整型一维数组 # @param k int整型 # @return int整型 # class Solution: def findMaxRangeWithinThreshold(self , heights , k ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ public int findMaxRangeWithinThreshold (List
heights, int k) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ function findMaxRangeWithinThreshold( heights , k ) { // write code here } module.exports = { findMaxRangeWithinThreshold : findMaxRangeWithinThreshold };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param heights int整型一维数组 # @param k int整型 # @return int整型 # class Solution: def findMaxRangeWithinThreshold(self , heights: List[int], k: int) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ func findMaxRangeWithinThreshold( heights []int , k int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param heightsLen int heights数组长度 * @param k int整型 * @return int整型 */ int findMaxRangeWithinThreshold(int* heights, int heightsLen, int k ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param heights int整型一维数组 # @param k int整型 # @return int整型 # class Solution def findMaxRangeWithinThreshold(heights, k) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ def findMaxRangeWithinThreshold(heights: Array[Int],k: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ fun findMaxRangeWithinThreshold(heights: IntArray,k: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ public int findMaxRangeWithinThreshold (int[] heights, int k) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ export function findMaxRangeWithinThreshold(heights: number[], k: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ func findMaxRangeWithinThreshold ( _ heights: [Int], _ k: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param k int整型 * @return int整型 */ pub fn findMaxRangeWithinThreshold(&self, heights: Vec
, k: i32) -> i32 { // write code here } }
[1, 5, 3, 10, 5, 4, 8],3
2