Skip to content

Commit

Permalink
Create 2554. Maximum Number of Integers to Choose From a Range I
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 6, 2024
1 parent 5d3fdcb commit 102b2b0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 2554. Maximum Number of Integers to Choose From a Range I
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int maxCount(vector<int>& banned, int n, int maxSum) {
unordered_map<int, bool> hash;
for (auto num: banned) {
hash[num] = 1;
}
int sum = 0, count = 0, i = 1;
while (i <= n) {
if (!hash[i]) {
if (sum + i > maxSum) return count;
sum += i;
count ++;
}
i++;
}
return count;
}
};

0 comments on commit 102b2b0

Please sign in to comment.