diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-10 09:23:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-10 09:23:35 +0100 |
| commit | 7ad8fdb1ba3d67e7d46ff5ed9527c200ab5dbc0e (patch) | |
| tree | 42245290f03bb21105d07b4ce5153c1c6b602cf4 /challenge-325/deadmarshal/java/Ch1.java | |
| parent | f9a0da9465d4b6745ede068698d1d59125a8a7ab (diff) | |
| parent | 8f7edcdf6fd5d1ecc837c050d7ca3298827fb4ac (diff) | |
| download | perlweeklychallenge-club-7ad8fdb1ba3d67e7d46ff5ed9527c200ab5dbc0e.tar.gz perlweeklychallenge-club-7ad8fdb1ba3d67e7d46ff5ed9527c200ab5dbc0e.tar.bz2 perlweeklychallenge-club-7ad8fdb1ba3d67e7d46ff5ed9527c200ab5dbc0e.zip | |
Merge pull request #12159 from deadmarshal/TWC325
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); + } +} + |
