diff options
| author | Ali <adeadmarshal@gmail.com> | 2025-07-08 11:14:43 +0330 |
|---|---|---|
| committer | Ali <adeadmarshal@gmail.com> | 2025-07-08 11:14:43 +0330 |
| commit | 0ea99ffa0f7495899afdcf95ef7cf9a3f224b940 (patch) | |
| tree | 6f33adcfaaaae33772539fcb2f38bebcc917d97d /challenge-329/deadmarshal/java/Ch1.java | |
| parent | bd7fce4bd5d085c209a213f2daca1e79799c9e87 (diff) | |
| download | perlweeklychallenge-club-0ea99ffa0f7495899afdcf95ef7cf9a3f224b940.tar.gz perlweeklychallenge-club-0ea99ffa0f7495899afdcf95ef7cf9a3f224b940.tar.bz2 perlweeklychallenge-club-0ea99ffa0f7495899afdcf95ef7cf9a3f224b940.zip | |
TWC329
Diffstat (limited to 'challenge-329/deadmarshal/java/Ch1.java')
| -rw-r--r-- | challenge-329/deadmarshal/java/Ch1.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-329/deadmarshal/java/Ch1.java b/challenge-329/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..b2302f5c4a --- /dev/null +++ b/challenge-329/deadmarshal/java/Ch1.java @@ -0,0 +1,27 @@ +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Ch1 { + public static void main(String[] args) { + System.out.println(counter_integers("the1weekly2challenge2")); + System.out.println(counter_integers("go21od1lu5c7k")); + System.out.println(counter_integers("4p3e2r1l")); + } + + private static List<String> counter_integers(String word) { + Set<String> s = new HashSet<>(); + int n = word.length(); + for (int i = 0; i < n; ++i) { + if (Character.isDigit(word.charAt(i))) { + while ((i < n) && (word.charAt(i) == '0')) ++i; + int j = i; + while ((j < n) && (Character.isDigit(word.charAt(j)))) ++j; + s.add(word.substring(i, j)); + i = j; + } + } + return s.stream().toList(); + } +} + |
