Skip to content

Commit ec29dff

Browse files
add 2549
1 parent 2318676 commit ec29dff

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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+
| 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 |
1112
| 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 |
1213
| 2540 |[Minimum Common Value](https://leetcode.com/problems/minimum-common-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2540.java) || Easy |
1314
| 2536 |[Increment Submatrices by One](https://leetcode.com/problems/increment-submatrices-by-one/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2536.java) || Medium |
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2549 {
7+
public static class Solution1 {
8+
public int distinctIntegers(int n) {
9+
Set<Integer> total = new HashSet<>();
10+
total.add(n);
11+
Set<Integer> setToGoThrough = new HashSet<>();
12+
setToGoThrough.add(n);
13+
Set<Integer> newSet = new HashSet<>();
14+
int days = 1000000000;
15+
int lastTotal = total.size();
16+
while (days-- > 0) {
17+
for (int num : setToGoThrough) {
18+
for (int i = 1; i <= num; i++) {
19+
if (num % i == 1 && !total.contains(i)) {
20+
newSet.add(i);
21+
}
22+
}
23+
}
24+
setToGoThrough = new HashSet<>(newSet);
25+
total.addAll(newSet);
26+
if (lastTotal == total.size()) {
27+
return total.size();
28+
}
29+
lastTotal = total.size();
30+
newSet.clear();
31+
}
32+
return total.size();
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)