<style>
html, body, .ui-content {
background: #222222;
color: #00BFFF;
}
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: linear-gradient(180deg, #2BE8CF60 0%, #2B83E860 100%);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: linear-gradient(180deg, #2BE8CF95 0%, #2B83E895 100%);
}
/* 設定 code 模板 */
.markdown-body code,
.markdown-body tt {
background-color: #ffffff36;
}
.markdown-body .highlight pre,
.markdown-body pre {
color: #ddd;
background-color: #00000036;
}
.hljs-tag {
color: #ddd;
}
.token.operator {
background-color: transparent;
}
</style>
###### tags: `Leetcode`
# 2567. Minimum Score by Changing Two Elements
###### Link : https://leetcode.com/problems/minimum-score-by-changing-two-elements/
## 題目
low為陣列中任兩數字的最小相差
high為陣列中任兩數字的最大相差
求兩者相加
## 程式碼
```cpp=
class Solution {
public:
//刪除最多兩個離群值,求最小的數字範圍
int minimizeSum(vector<int>& nums) {
sort(nums.begin(), nums.end());
//將low固定為0,只需算high
int ans = nums.back() - nums[0], n = nums.size();
ans = min(ans, nums[n - 3] - nums[0]);//刪除最後兩個
ans = min(ans, nums[n - 2] - nums[1]);//刪除最後一個和第一個
ans = min(ans, nums[n - 1] - nums[2]);//刪除前兩個
return ans;
}
};
```