Skip to content

Commit 5c67f83

Browse files
add 1805
1 parent 51f67fc commit 5c67f83

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1805|[Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1805.java) ||Medium|String|
1112
|1800|[Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1800.java) ||Easy|Two Pointers|
1213
|1797|[Design Authentication Manager](https://leetcode.com/problems/design-authentication-manager/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1797.java) ||Medium|HashTable, Design|
1314
|1796|[Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1796.java) ||Easy|String|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _1805 {
7+
public static class Solution1 {
8+
public int numDifferentIntegers(String word) {
9+
StringBuilder sb = new StringBuilder();
10+
for (int i = 0; i < word.length(); i++) {
11+
if (!Character.isDigit(word.charAt(i))) {
12+
sb.append(" ");
13+
} else {
14+
sb.append(word.charAt(i));
15+
}
16+
}
17+
String[] numbers = sb.toString().split("\\s+");
18+
Set<String> set = new HashSet<>();
19+
for (String num : numbers) {
20+
if (!num.isEmpty()) {
21+
set.add(num.replaceFirst("^0+(?!$)", ""));
22+
}
23+
}
24+
return set.size();
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)