Skip to content

Commit d8b8359

Browse files
authored
Merge pull request #2672 from flashzzz/main
Create 2554-maximum-number-of-integers-to-choose-from-a-range-I.py
2 parents 2bc2fd9 + 66b72f3 commit d8b8359

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:
3+
nums = {x:1 for x in range(1, n + 1)} # hashmap for storing the required elements
4+
for i in banned:
5+
if nums.get(i):
6+
del nums[i]
7+
sum = 0
8+
count = 0
9+
for i in nums:
10+
sum += i
11+
if sum <= maxSum:
12+
count += 1
13+
else:
14+
break
15+
return count

0 commit comments

Comments
 (0)