Number of Different Integers in a String LeetCode solution in Java
1class Solution {2public int numDifferentIntegers(String word) {3String[] arr = word.replaceAll("[a-zA-Z]", " ").split("\\s+");4Set<String> set = new HashSet<String>();56for (String str : arr) {7if (!str.isEmpty()) set.add(String.valueOf(str.replaceAll("^0*", "")));8}910return set.size();11}12}