Description
Submission
brute-force + pruning
class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { if(matrix.empty()) return false; if(matrix[0].empty()) return false; int n = matrix.size(); int m = matrix[0].size(); for(int i = 0; i < n; ++i) { if(matrix[i][0] > target) continue; if(matrix[i][m-1] < target) continue; for(int j = 0; j < m; ++j) { if(target == matrix[i][j]) return true; } } return false; } };