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

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

LeetCode 6929. 數(shù)組的最大美麗值

2023-07-16 12:43 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?array?nums?and a?non-negative?integer?k.

In one operation, you can do the following:

  • Choose an index?i?that?hasn't been chosen before?from the range?[0, nums.length - 1].

  • Replace?nums[i]?with any integer from the range?[nums[i] - k, nums[i] + k].

The?beauty?of the array is the length of the longest subsequence consisting of equal elements.

Return?the?maximum?possible beauty of the array?nums?after applying the operation any number of times.

Note?that you can apply the operation to each index?only once.

A?subsequence?of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.

?

Example 1:

Input: nums = [4,6,1,2], k = 2

Output: 3

Explanation: In this example, we apply the following operations: - Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2]. - Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4]. After the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3). It can be proven that 3 is the maximum possible length we can achieve.

Example 2:

Input: nums = [1,1,1,1], k = 10

Output: 4

Explanation: In this example we don't have to apply any operations. The beauty of the array nums is 4 (whole array).

-------------------------------------

給你一個(gè)下標(biāo)從 0 開(kāi)始的整數(shù)數(shù)組 nums 和一個(gè) 非負(fù) 整數(shù) k 。


在一步操作中,你可以執(zhí)行下述指令:


在范圍 [0, nums.length - 1] 中選擇一個(gè) 此前沒(méi)有選過(guò) 的下標(biāo) i 。

將 nums[i] 替換為范圍 [nums[i] - k, nums[i] + k] 內(nèi)的任一整數(shù)。

數(shù)組的 美麗值 定義為數(shù)組中由相等元素組成的最長(zhǎng)子序列的長(zhǎng)度。


對(duì)數(shù)組 nums 執(zhí)行上述操作任意次后,返回?cái)?shù)組可能取得的 最大 美麗值。


注意:你 只 能對(duì)每個(gè)下標(biāo)執(zhí)行 一次 此操作。


數(shù)組的 子序列 定義是:經(jīng)由原數(shù)組刪除一些元素(也可能不刪除)得到的一個(gè)新數(shù)組,且在此過(guò)程中剩余元素的順序不發(fā)生改變。


?


示例 1:


輸入:nums = [4,6,1,2], k = 2

輸出:3

解釋?zhuān)涸谶@個(gè)示例中,我們執(zhí)行下述操作:

- 選擇下標(biāo) 1 ,將其替換為 4(從范圍 [4,8] 中選出),此時(shí) nums = [4,4,1,2] 。

- 選擇下標(biāo) 3 ,將其替換為 4(從范圍 [0,4] 中選出),此時(shí) nums = [4,4,1,4] 。

執(zhí)行上述操作后,數(shù)組的美麗值是 3(子序列由下標(biāo) 0 、1 、3 對(duì)應(yīng)的元素組成)。

可以證明 3 是我們可以得到的由相等元素組成的最長(zhǎng)子序列長(zhǎng)度。

示例 2:


輸入:nums = [1,1,1,1], k = 10

輸出:4

解釋?zhuān)涸谶@個(gè)示例中,我們無(wú)需執(zhí)行任何操作。

數(shù)組 nums 的美麗值是 4(整個(gè)數(shù)組)。

?


提示:


1 <= nums.length <= 105

0 <= nums[i], k <= 105

-------------------------

以2k為區(qū)間,找區(qū)間內(nèi)元素的最大值,題目信息一轉(zhuǎn)換,就知道怎么做了,沒(méi)錯(cuò),我還是一如既往的笨;

執(zhí)行用時(shí):39 ms, 在所有?Java?提交中擊敗了100.00%的用戶(hù)

內(nèi)存消耗:57 MB, 在所有?Java?提交中擊敗了100.00%的用戶(hù)


LeetCode 6929. 數(shù)組的最大美麗值的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
平湖市| 昌邑市| 南丰县| 化州市| 东乌珠穆沁旗| 华蓥市| 和田市| 舒城县| 吉隆县| 吴忠市| 东丰县| 长岛县| 穆棱市| 社旗县| 滁州市| 定安县| 南京市| 芒康县| 岳西县| 凤庆县| 应城市| 承德县| 曲松县| 富宁县| 登封市| 南通市| 健康| 临江市| 河津市| 亚东县| 大足县| 珲春市| 米脂县| 沂南县| 临西县| 宁乡县| 屯门区| 长葛市| 佛教| 高青县| 九龙县|