Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
smallest-range-ii.cpp 426 Bytes
Copy Edit Raw Blame History
kamyu authored 2018-09-23 21:54 +08:00 . Create smallest-range-ii.cpp
// Time: O(nlogn)
// Space: O(1)
class Solution {
public:
int smallestRangeII(vector<int>& A, int K) {
sort(A.begin(), A.end());
int result = A.back() - A.front();
for (int i = 0; i < A.size() - 1; ++i) {
result = min(result,
max(A.back() - K, A[i] + K) -
min(A.front() + K, A[i + 1] - K));
}
return result;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search