Number of Different Integers in a String LeetCode solution in Java

1
class Solution {
2
public int numDifferentIntegers(String word) {
3
String[] arr = word.replaceAll("[a-zA-Z]", " ").split("\\s+");
4
Set<String> set = new HashSet<String>();
5

6
for (String str : arr) {
7
if (!str.isEmpty()) set.add(String.valueOf(str.replaceAll("^0*", "")));
8
}
9

10
return set.size();
11
}
12
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0