Skip to content

Commit 700abbe

Browse files
add 2554
1 parent 218284b commit 700abbe

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2554 |[Maximum Number of Integers to Choose From a Range I](https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2554.java) | | Medium |
1112
| 2553 |[Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2553.java) | | Easy |
1213
| 2549 |[Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2549.java) || Easy |
1314
| 2544 |[Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2544.java) | [:tv:](https://youtu.be/IFRYDmhEWGw) | Easy |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2554 {
7+
public static class Solution1 {
8+
public int maxCount(int[] banned, int n, int maxSum) {
9+
Set<Integer> set = new HashSet<>();
10+
for (int b : banned) {
11+
set.add(b);
12+
}
13+
int maxCnt = 0;
14+
int sum = 0;
15+
for (int i = 1; i <= n; i++) {
16+
if (!set.contains(i)) {
17+
if (sum + i > maxSum) {
18+
return maxCnt;
19+
} else {
20+
sum += i;
21+
maxCnt++;
22+
}
23+
}
24+
}
25+
return maxCnt;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy