public class Solution { public bool SearchMatrix(int[,] matrix, int target) { int i = 0, j = matrix.GetLength(1) - 1; while (i < matrix.GetLength(0) && j >= 0) { int x = matrix[i, j]; if (target == x) { return true; } else if (target < x) { j--; } else { i++; } } return false; } }