MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / searchMatrix

Method searchMatrix

240. Search a 2D Matrix II/Solution.cpp:15–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13class Solution {
14public:
15 bool searchMatrix(vector<vector<int>>& matrix, int target) {
16 int x = matrix.size();
17 if (x < 1) return false;
18 int y = matrix[0].size();
19 if (y < 1) return false;
20 int i = x - 1, j = 0;
21 while (i >= 0 and j < y) {
22 if (matrix[i][j] == target) return true;
23 else if (matrix[i][j] < target) j ++ ;
24 else if (matrix[i][j] > target) i -- ;
25 }
26 return false;
27 }
28};
29
30int main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected