Created
March 26, 2016 17:47
-
-
Save deyindra/922d2bfc0b3e47419d59 to your computer and use it in GitHub Desktop.
Find Count in 2 dimensional Matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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