Method
findElement
(int[][] matrix, int elem)
Source from the content-addressed store, hash-verified
| 4 | public class QuestionA { |
| 5 | |
| 6 | public static boolean findElement(int[][] matrix, int elem) { |
| 7 | int row = 0; |
| 8 | int col = matrix[0].length - 1; |
| 9 | while (row < matrix.length && col >= 0) { |
| 10 | if (matrix[row][col] == elem) { |
| 11 | return true; |
| 12 | } else if (matrix[row][col] > elem) { |
| 13 | col--; |
| 14 | } else { |
| 15 | row++; |
| 16 | } |
| 17 | } |
| 18 | return false; |
| 19 | } |
| 20 | |
| 21 | public static void main(String[] args) { |
| 22 | int M = 10; |
Tested by
no test coverage detected