We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b2072a4 commit 9491375Copy full SHA for 9491375
Easy/Number of Different Integers in a String.java
@@ -0,0 +1,18 @@
1
+class Solution {
2
+ public int numDifferentIntegers(String word) {
3
+ Set<Integer> set = new HashSet<>();
4
+ int idx = 0;
5
+ int n = word.length();
6
+ while (idx < n) {
7
+ if (Character.isDigit(word.charAt(idx))) {
8
+ int num = 0;
9
+ while (idx < n && Character.isDigit(word.charAt(idx))) {
10
+ num = num * 10 + Character.getNumericValue(word.charAt(idx++));
11
+ }
12
+ set.add(num);
13
14
+ idx++;
15
16
+ return set.size();
17
18
+}
0 commit comments