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

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

 

posted @ 2018-09-23 11:12  Asurudo  阅读(560)  评论(4编辑  收藏  举报