2587. Rearrange Array to Maximize Prefix Score 發表於 2023-03-19 | 分類於 leetcode problemsolution123456789101112131415class Solution {public: int maxScore(vector<int>& nums) { sort(nums.begin(), nums.end(), greater<int>()); int count = (nums.front()>0)?1:0; long long cur = nums[0]; for(int i=0;i<nums.size() ; ++i) { if(i==0) continue; cur += nums[i]; if(cur > 0) count++; else break; } return count ; }}; analysis time complexity O(nlogn) space complexity O(1)