1. 程式人生 > >Leetcode-908 Smallest Range I(最小差值 I)

Leetcode-908 Smallest Range I(最小差值 I)

min 最小 max small style turn tco ret vector

 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 };

Leetcode-908 Smallest Range I(最小差值 I)