MCPcopy Create free account
hub / github.com/careercup/ctci / findElement

Method findElement

java/Chapter 11/Question11_6/QuestionA.java:6–19  ·  view source on GitHub ↗
(int[][] matrix, int elem)

Source from the content-addressed store, hash-verified

4public 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;

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected