classSolution { public: intsmallestRangeI(vector<int>& nums, int k){ int min = 10000, max = 0; for(int i = 0; i < nums.size(); i++){ if(min > nums[i]) // 找最小值 min = nums[i]; if(max < nums[i]) // 找最大值 max = nums[i]; } if(max - min <= k * 2){ return0; } return (max - min - k * 2); } };