从右上角往左下角看,是一个二叉搜索树
class Solution { public: bool findn(vector<vector<int>> &matrix, int target, int x, int y) { if (matrix.size() == 0) { return false; } else { if (x < 0 || x >= matrix.size() || y < 0 || y >= matrix[0].size()) return false; if (matrix[x][y] == target) return true; else if (target < matrix[x][y]) { return findn(matrix, target, x, y - 1); } else { return findn(matrix, target, x + 1, y); } } } bool findNumberIn2DArray(vector<vector<int>> &matrix, int target) { if(matrix.size()==0) return false; int a = matrix[0].size() - 1; return findn(matrix, target, 0, matrix[0].size() - 1); } };