Skip to content

Commit

Permalink
Create smallest-range-i.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Sep 23, 2018
1 parent a59e601 commit 2162741
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions C++/smallest-range-i.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Time: O(n)
// Space: O(1)

class Solution {
public:
int smallestRangeI(vector<int>& A, int K) {
return max(0, *max_element(A.cbegin(), A.cend()) -
*min_element(A.cbegin(), A.cend()) -
2 * K);
}
};

0 comments on commit 2162741

Please sign in to comment.