Skip to content

Commit 351a9d4

Browse files
committed
update
1 parent 4209297 commit 351a9d4

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

leetcode_solved/[editing]leetcode_0887_Super_Egg_Drop.cpp

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// AC: T:O(n) S:O(n)
2+
// Runtime: 2 ms, faster than 100.00% of Java online submissions for Number of Different Integers in a String.
3+
// Memory Usage: 39.3 MB, less than 100.00% of Java online submissions for Number of Different Integers in a String.
4+
//
5+
// 注意坑:
6+
// 1.里面说包含 Integer,但没说 integer 范围,所以去重时不要用 int 去存结果,会溢出。
7+
// 2.字符串表示时数字位大于等于两位时,要去掉头部的0
8+
//
9+
class Solution {
10+
public int numDifferentIntegers(String word) {
11+
int size = word.length();
12+
int aAscii = 'a';
13+
int zAscii = 'z';
14+
int zeroAscii = '0';
15+
HashSet<String> record = new HashSet<>();
16+
for(int i = aAscii; i <= zAscii; i++) {
17+
word = word.replace((char) i, ' ');
18+
}
19+
String[] ret = word.split(" ");
20+
for (String item: ret) {
21+
if (item.isEmpty()) {
22+
continue;
23+
}
24+
// 去除头部0
25+
int pos = 0;
26+
while(item.charAt(pos) == zeroAscii && item.length() >= 2) {
27+
item = item.substring(1);
28+
}
29+
record.add(item);
30+
}
31+
32+
return record.size();
33+
}
34+
}

0 commit comments

Comments
 (0)