#include "leetcode.h" class Solution { public: bool searchMatrix(vector> &matrix, int target) { int m = matrix.size(), n = matrix[0].size(); if (m == 0) return false; int i = 0, j = n - 1; while (i < m && j >= 0) { if (matrix[i][j] == target) return true; else if (matrix[i][j] > target) j--; else i++; } return false; } };