国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

Leetcode 2592. Maximize Greatness of an Array

2023-03-19 13:11 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a 0-indexed integer array?nums. You are allowed to permute?nums?into a new array?perm?of your choosing.

We define the?greatness?of?nums?be the number of indices?0 <= i < nums.length?for which?perm[i] > nums[i].

Return?the?maximum?possible greatness you can achieve after permuting?nums.

?

Example 1:

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

Output: 4

Explanation:?

One of the optimal rearrangements is perm = [2,5,1,3,3,1,1]. At indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.

Example 2:

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

Output: 3

Explanation: We can prove the optimal perm is [2,3,4,1]. At indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3.

想啊想,用隊列還是優(yōu)先隊列。。。結果不需要額外的空間,自己跟跟自己去比對,2個指針就可以。。。我真的還是太笨了


Runtime:?11 ms, faster than?100.00%?of?Java?online submissions for?Maximize Greatness of an Array.

Memory Usage:?59.4 MB, less than?100.00%?of?Java?online submissions for?Maximize Greatness of an Array.


Leetcode 2592. Maximize Greatness of an Array的評論 (共 條)

分享到微博請遵守國家法律
太康县| 宜都市| 荣成市| 和龙市| 自贡市| 宁城县| 奉新县| 监利县| 沈阳市| 肥东县| 吉安县| 马鞍山市| 桦甸市| 珲春市| 淳化县| 清涧县| 巧家县| 彭山县| 襄城县| 永康市| 彭泽县| 海门市| 南和县| 蒙自县| 阳西县| 来安县| 阿拉善盟| 澄城县| 驻马店市| 灵台县| 乌鲁木齐县| 建平县| 扎囊县| 长丰县| 沅江市| 涞水县| 郴州市| 大方县| 绥棱县| 将乐县| 洪雅县|