Skip to content

Commit f1e6b17

Browse files
solves #2729: Check if The Number is Fascinating in java
1 parent 40399af commit f1e6b17

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@
830830
| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | |
831831
| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | |
832832
| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | |
833-
| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | | |
833+
| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | |
834834
| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | | |
835835
| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | |
836836
| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | |
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// https://leetcode.com/problems/check-if-the-number-is-fascinating
2+
// T: O(log(N))
3+
// S: O(1)
4+
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
8+
public class CheckIfTheNumberIsFascinating {
9+
public boolean isFascinating(int number) {
10+
final String modifiedNumber = "" + number + (2 * number) + (3 * number);
11+
final Set<Character> digits = toSet(modifiedNumber);
12+
return digits.size() == 9 && !digits.contains('0') && modifiedNumber.length() == 9;
13+
}
14+
15+
private Set<Character> toSet(String str) {
16+
final Set<Character> set = new HashSet<>();
17+
for (int i = 0 ; i < str.length() ; i++) {
18+
set.add(str.charAt(i));
19+
}
20+
return set;
21+
}
22+
}

0 commit comments

Comments
 (0)