2600. K Items With the Maximum Sum 發表於 2023-12-21 | 分類於 leetcode problemsolution12345678910111213class Solution {public: int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { int ret = 0; if(numOnes >= k) return k; if(numOnes < k) ret = numOnes; k-=numOnes; if(numZeros >= k) return ret; k-=numZeros; return ret-k; }}; analysis time complexity O(1) space complexity O(1)