-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasy_3032.java
More file actions
30 lines (25 loc) · 821 Bytes
/
easy_3032.java
File metadata and controls
30 lines (25 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 3032. Count Numbers With Unique Digits II
public class Solution {
public int numberCount(int a, int b) {
List<Integer> fullRange = new ArrayList<>();
int counter = 0;
for (int i = a; i <= b; i++) {
fullRange.add(i);
}
for (int j = 0; j < fullRange.size(); j++) {
String numStr = String.valueOf(fullRange.get(j));
Set<Character> uniqueDigits = new HashSet<>();
boolean hasDuplicate = false;
for (int k = 0; k < numStr.length(); k++) {
if (!uniqueDigits.add(numStr.charAt(k))) {
hasDuplicate = true;
break;
}
}
if (!hasDuplicate) {
counter++;
}
}
return counter;
}
}