forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1805.java
27 lines (25 loc) · 831 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
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _1805 {
public static class Solution1 {
public int numDifferentIntegers(String word) {
StringBuilder sb = new StringBuilder();
for (int i = 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 = new HashSet<>();
for (String num : numbers) {
if (!num.isEmpty()) {
set.add(num.replaceFirst("^0+(?!$)", ""));
}
}
return set.size();
}
}
}