aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/deadmarshal/java/Ch1.java
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-325/deadmarshal/java/Ch1.java')
-rw-r--r--challenge-325/deadmarshal/java/Ch1.java20
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);
+ }
+}
+