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

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

LeetCode 2593. Find Score of an Array After Marking All Elements

2023-04-11 09:42 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an array?nums?consisting of positive integers.

Starting with?score = 0, apply the following algorithm:

  • Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.

  • Add the value of the chosen integer to?score.

  • Mark?the chosen element and its two adjacent elements if they exist.

  • Repeat until all the array elements are marked.

Return?the score you get after applying the above algorithm.

?

Example 1:

Input: nums = [2,1,3,4,5,2]

Output: 7

Explanation:?

We mark the elements as follows:?

- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].?

- 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].?

- 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].?

Our score is 1 + 2 + 4 = 7.

Example 2:

Input: nums = [2,3,5,1,3,2]

Output: 5

Explanation: We mark the elements as follows:?

- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].?

- 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].?

- 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].

Our score is 1 + 2 + 2 = 5.

?

Constraints:

  • 1 <= nums.length <= 105

  • 1 <= nums[i] <= 106

這里面最主要的是如何定義優(yōu)先隊(duì)列的排序規(guī)則,

這個規(guī)則定義好之后,用一個數(shù)組記錄被訪問過的元素即可。

屬于新知識,學(xué)習(xí)到了。


Runtime:?267 ms, faster than?40.49%?of?Java?online submissions for?Find Score of an Array After Marking All Elements.

Memory Usage:?60.6 MB, less than?25.56%?of?Java?online submissions for?Find Score of an Array After Marking All Elements.



LeetCode 2593. Find Score of an Array After Marking All Elements的評論 (共 條)

分享到微博請遵守國家法律
嵊州市| 邻水| 临猗县| 福泉市| 玉门市| 商都县| 桂林市| 秀山| 琼中| 新丰县| 建宁县| 安新县| 忻城县| 平原县| 依安县| 且末县| 甘肃省| 平顺县| 盐亭县| 年辖:市辖区| 固镇县| 防城港市| 惠来县| 左贡县| 石渠县| 永康市| 龙岩市| 利辛县| 民和| 十堰市| 湟中县| 青浦区| 罗定市| 怀仁县| 建阳市| 资兴市| 黔江区| 渭源县| 偏关县| 云龙县| 张家口市|