- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1805.java
27 lines (25 loc) · 846 Bytes
/
_1805.java
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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.HashSet;
importjava.util.Set;
publicclass_1805 {
publicstaticclassSolution1 {
publicintnumDifferentIntegers(Stringword) {
StringBuildersb = newStringBuilder();
for (inti = 0; i < word.length(); i++) {
if (!Character.isDigit(word.charAt(i))) {
sb.append(" ");
} else {
sb.append(word.charAt(i));
}
}
String[] numbers = sb.toString().split("\\s+");
Set<String> set = newHashSet<>();
for (Stringnum : numbers) {
if (!num.isEmpty()) {
set.add(num.replaceFirst("^0+(?!$)", ""));
}
}
returnset.size();
}
}
}