int smallestRangeI(vector & A, int K) { int min = INT_MAX; int max = INT_MIN; for (auto a : A) { if (min > a) { min = a; } if (max < a) { max = a; } } int dif = max - min; if (dif > 2 * K) { return dif - 2 * K; } else { return 0; }}
本文共 414 字,大约阅读时间需要 1 分钟。
int smallestRangeI(vector & A, int K) { int min = INT_MAX; int max = INT_MIN; for (auto a : A) { if (min > a) { min = a; } if (max < a) { max = a; } } int dif = max - min; if (dif > 2 * K) { return dif - 2 * K; } else { return 0; }}
转载于:https://www.cnblogs.com/asenyang/p/9714728.html