diff --git a/C++/smallest-range-i.cpp b/C++/smallest-range-i.cpp new file mode 100644 index 000000000..63a7bb6a5 --- /dev/null +++ b/C++/smallest-range-i.cpp @@ -0,0 +1,11 @@ +// Time: O(n) +// Space: O(1) + +class Solution { +public: + int smallestRangeI(vector& A, int K) { + return max(0, *max_element(A.cbegin(), A.cend()) - + *min_element(A.cbegin(), A.cend()) - + 2 * K); + } +};