五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 2567. Minimum Score by Changing Two Elements

2023-04-19 14:28 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?integer array?nums.

  • The?low?score of?nums?is the minimum value of?|nums[i]?- nums[j]|?over all?0 <= i < j < nums.length.

  • The?high?score of?nums?is the maximum value of?|nums[i]?- nums[j]|?over all?0 <= i < j < nums.length.

  • The?score?of?nums?is the sum of the?high?and?low?scores of nums.

To minimize the score of?nums, we can change the value of?at most two?elements of?nums.

Return?the?minimum?possible?score?after changing?the value of?at most two?elements of?nums.

Note that?|x|?denotes the absolute value of?x.

?

Example 1:

Input: nums = [1,4,3]

Output: 0

Explanation:?

Change value of nums[1] and nums[2] to 1 so that nums becomes [1,1,1].?

Now, the value of |nums[i] - nums[j]| is always equal to 0, so we return 0 + 0 = 0.

Example 2:

Input: nums = [1,4,7,8,5]

Output: 3

Explanation:?

Change nums[0] and nums[1] to be 6. Now nums becomes [6,6,7,8,5].?

Our low score is achieved when i = 0 and j = 1,?

in which case |nums[i] - nums[j]| = |6 - 6| = 0.?

Our high score is achieved when i = 3 and j = 4,?

in which case |nums[i] - nums[j]| = |8 - 5| = 3.?

The sum of our high and low score is 3, which we can prove to be minimal.

?

Constraints:

  • 3 <= nums.length <= 105

  • 1 <= nums[i] <= 109

只要更改數(shù)字了,那么low數(shù)字永遠(yuǎn)就是0,剩下的就是看最大值了,

要么改變2個(gè)大的,

要么改變2個(gè)小的,

要么改變1大1小。

這三種情況,求對(duì)應(yīng)的最小值即可。

sort一下就好了。所以代碼就很短了。


Runtime:?17 ms, faster than?72.85%?of?Java?online submissions for?Minimum Score by Changing Two Elements.

Memory Usage:?56.5 MB, less than?6.59%?of?Java?online submissions for?Minimum Score by Changing Two Elements.


LeetCode 2567. Minimum Score by Changing Two Elements的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
永川市| 修水县| 临邑县| 通海县| 香格里拉县| 福建省| 进贤县| 邮箱| 孟村| 乌鲁木齐县| 镇安县| 高青县| 怀仁县| 炉霍县| 朔州市| 天气| 邓州市| 徐州市| 晋江市| 兴山县| 乌拉特后旗| 扶绥县| 合江县| 环江| 巧家县| 海南省| 永川市| 北辰区| 丹棱县| 濉溪县| 应用必备| 镇雄县| 清涧县| 滕州市| 牙克石市| 曲阳县| 恩施市| 屯留县| 文登市| 昭苏县| 侯马市|