1 class Solution 2 { 3 public: 4 int smallestRangeI(vector<int>& A, int K) 5 { 6 int Max = INT_MIN; 7 int Min = INT_MAX; 8 for(auto d:A) 9 { 10 if(d > Max) 11 Max = d; 12 if(d < Min) 13 Min = d; 14 } 15 16 if(Min+2*K>=Max) 17 return 0; 18 else 19 return Max-Min-2*K; 20 } 21 };
原文地址:https://www.cnblogs.com/Asurudo/p/9692228.html
时间: 2024-11-08 13:07:53