class Solution {
public int numDifferentIntegers(String word) {
char[] chars = word.toCharArray();
int n = chars.length;
Set<String> set = new HashSet<>();
for (int i = 0; i < n; i++) {
int temp = 0;
boolean flag = false;
boolean zero = true;
StringBuilder stringBuilder = new StringBuilder();
while (i < n && chars[i] >= '0' && chars[i] <= '9') {
flag = true;
if (zero && chars[i] == '0') {
i++;
continue;
}
zero = false;
stringBuilder.append(chars[i]);
i++;
}
if (flag) {
set.add(stringBuilder.length() == 0 ? "0" : stringBuilder.toString());
}
}
return set.size();
}
}
标签:1805,int,chars,整数,boolean,&&,字符串
From: https://www.cnblogs.com/eiffelzero/p/16958389.html