Skip to content

Commit 0defde5

Browse files
authored
Create 2554. Maximum Number of Integers to Choose From a Range I (#653)
2 parents 5d3fdcb + 102b2b0 commit 0defde5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int maxCount(vector<int>& banned, int n, int maxSum) {
4+
unordered_map<int, bool> hash;
5+
for (auto num: banned) {
6+
hash[num] = 1;
7+
}
8+
int sum = 0, count = 0, i = 1;
9+
while (i <= n) {
10+
if (!hash[i]) {
11+
if (sum + i > maxSum) return count;
12+
sum += i;
13+
count ++;
14+
}
15+
i++;
16+
}
17+
return count;
18+
}
19+
};

0 commit comments

Comments
 (0)