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

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

Leetcode 2587. Rearrange Array to Maximize Prefix Score

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

You are given a?0-indexed?integer array?nums. You can rearrange the elements of?nums?to?any order?(including the given order).

Let?prefix?be the array containing the prefix sums of?nums?after rearranging it. In other words,?prefix[i]?is the sum of the elements from?0?to?i?in?nums?after rearranging it. The?score?of?nums?is the number of positive integers in the array?prefix.

Return?the maximum score you can achieve.

?

Example 1:

Input: nums = [2,-1,0,1,-3,3,-3]

Output: 6

Explanation: We can rearrange the array into nums = [2,3,1,-1,-3,0,-3]. prefix = [2,5,6,5,2,2,-1], so the score is 6. It can be shown that 6 is the maximum score we can obtain.

Example 2:

Input: nums = [-2,-3,0]

Output: 0

Explanation: Any rearrangement of the array will result in a score of 0.

?

Constraints:

  • 1 <= nums.length <= 105

  • -106?<= nums[i] <= 106

  • 忘記int溢出的情況了,要是早點(diǎn)用long,也不至于只AC一道題。。。。


Runtime:?34 ms, faster than?100.00%?of?Java?online submissions for?Rearrange Array to Maximize Prefix Score.

Memory Usage:?59.3 MB, less than?100.00%?of?Java?online submissions for?Rearrange Array to Maximize Prefix Score.


Leetcode 2587. Rearrange Array to Maximize Prefix Score的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
章丘市| 建德市| 鄯善县| 楚雄市| 阜平县| 新绛县| 日喀则市| 卓尼县| 正蓝旗| 昂仁县| 南丹县| 双牌县| 宁德市| 奉新县| 九龙坡区| 乾安县| 宁强县| 双江| 屏山县| 宣恩县| 通州区| 安徽省| 凯里市| 江永县| 峨边| 沂南县| 烟台市| 永平县| 阿拉善右旗| 伊宁市| 凌海市| 民勤县| 海丰县| 铜山县| 扎兰屯市| 八宿县| 七台河市| 林西县| 大理市| 鹿泉市| 获嘉县|