problem:https://leetcode.com/problems/search-a-2d-matrix-ii
经典双指针二分查找题目。
class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int m = matrix.size(); if(!m) return false; int n = matrix[0].size(); if(!n) return false; int i = 0; int j = n - 1; while(i < m && j >= 0) { if(target == matrix[i][j]) return true; else if(target > matrix[i][j]) i++; else j--; } return false; } };
原文地址:https://www.cnblogs.com/fish1996/p/11335373.html
时间: 2024-10-06 12:00:14