Skip to content

Instantly share code, notes, and snippets.

@deyindra
Created March 26, 2016 17:47
Show Gist options
  • Save deyindra/922d2bfc0b3e47419d59 to your computer and use it in GitHub Desktop.
Save deyindra/922d2bfc0b3e47419d59 to your computer and use it in GitHub Desktop.
Find Count in 2 dimensional Matrix
public interface Predicate<T>{
boolean process(T object);
}
public static <T> int findCount(T[][] array, Predicate<T> predicate){
int count=0;
int row=0;
int col = array[0].length-1;
while (row<=array.length-1 && col>=0){
T value = array[row][col];
if(!predicate.process(value)){
col--;
}else{
count+=(col+1);
row++;
}
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment