Count of 1 in a sorted binary array GFG

 package com.company;


public class Count1S {
// Counting the number of 1 in binary sorted array
public static int getCount(int[] arr) {
int n = arr.length;
int first = countOccurrence.firstIndex(arr, 1);
if (first == -1) {
return 0;
}
return (n - first) ;
}

public static void main(String[] args) {
int[] array = {0, 0, 0, 1, 1, 1, 1};
System.out.println(getCount(array));
}
}

Comments