# 2587. Rearrange Array to Maximize Prefix Score ###### tags: `Leetcode` `Medium` `Greedy` Link: https://leetcode.com/problems/rearrange-array-to-maximize-prefix-score/description/ ## 思路 把nums从大到小排 prefix score肯定是最大的 ## Code ```python= class Solution: def maxScore(self, nums: List[int]) -> int: nums.sort(reverse=True) ans = currSum = 0 for num in nums: currSum += num if currSum > 0: ans += 1 else: break return ans ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up