Skip to content

Commit 3c0f8f7

Browse files
committed
Add C++ solution of problem #2554
1 parent 5267e40 commit 3c0f8f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2554/solution.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int maxCount(vector<int>& banned, int n, int maxSum) {
4+
unordered_set<int> m(begin(banned), end(banned));
5+
int ans = 0;
6+
int tmp = 0;
7+
for(int i = 1; i <= n; i++) {
8+
if(m.count(i))
9+
continue;
10+
11+
if(tmp + i > maxSum)
12+
break;
13+
tmp += i;
14+
ans++;
15+
}
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)