feat: 2025-10-24打卡
This commit is contained in:
26
908.smallest-range-i.java
Normal file
26
908.smallest-range-i.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* @lc app=leetcode id=908 lang=java
|
||||
*
|
||||
* [908] Smallest Range I
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public int smallestRangeI(int[] nums, int k) {
|
||||
if(nums == null || nums.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int min = nums[0], max = nums[0];
|
||||
for(int i = 1; i < nums.length; i++) {
|
||||
if(nums[i] < min) {
|
||||
min = nums[i];
|
||||
}
|
||||
if(nums[i] > max) {
|
||||
max = nums[i];
|
||||
}
|
||||
}
|
||||
return max - min > 2 * k ? max - min - 2 * k : 0;
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user