diff options
| author | Ali <adeadmarshal@gmail.com> | 2025-06-09 21:30:05 +0330 |
|---|---|---|
| committer | Ali <adeadmarshal@gmail.com> | 2025-06-09 21:30:05 +0330 |
| commit | 8f7edcdf6fd5d1ecc837c050d7ca3298827fb4ac (patch) | |
| tree | 8503fdd15b625892a248843d868b9ed84c2a3424 /challenge-325/deadmarshal/java/Ch1.java | |
| parent | e28477d2418099cfbb1a227133c69ddef6eed741 (diff) | |
| download | perlweeklychallenge-club-8f7edcdf6fd5d1ecc837c050d7ca3298827fb4ac.tar.gz perlweeklychallenge-club-8f7edcdf6fd5d1ecc837c050d7ca3298827fb4ac.tar.bz2 perlweeklychallenge-club-8f7edcdf6fd5d1ecc837c050d7ca3298827fb4ac.zip | |
TWC325
Diffstat (limited to 'challenge-325/deadmarshal/java/Ch1.java')
| -rw-r--r-- | challenge-325/deadmarshal/java/Ch1.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-325/deadmarshal/java/Ch1.java b/challenge-325/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..f1f27e332c --- /dev/null +++ b/challenge-325/deadmarshal/java/Ch1.java @@ -0,0 +1,20 @@ +public class Ch1 { + public static void main(String[] args) { + System.out.println(consecutive_one(new int[]{0, 1, 1, 0, 1, 1, 1})); + System.out.println(consecutive_one(new int[]{0, 0, 0, 0})); + System.out.println(consecutive_one(new int[]{1, 0, 1, 0, 1, 1})); + } + + private static int consecutive_one(int[] arr) { + int count = 0, res = 0; + for (int e : arr) { + if (e == 1) count++; + else { + res = Math.max(res, count); + count = 0; + } + } + return Math.max(count, res); + } +} + |
