2834. Find the Minimum Possible Sum of a Beautiful Array 發表於 2023-12-21 | 分類於 leetcode problemsolution1234567891011121314151617class Solution {public: long long minimumPossibleSum(int n, int target) { int cur = 1; long long ret = 1; unordered_set<int> unallowed ; unallowed.insert(target - cur); for(int i = 1;i<n;++i) { cur++; while(unallowed.count(cur)) cur++; ret+=cur; unallowed.insert(target - cur); } return ret; }}; analysis time complexity O(n) space complexity O(n)