标签:search a 2d matrix leetcode array binary search
class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { if(matrix.size() == 0) return false; bool result = false; int row = 0, col = matrix[0].size() - 1; while(row < matrix.size() && col >=0) { if(matrix[row][col] == target) { return true; } else if(matrix[row][col] > target) { col--; } else { row++; } } return result; } };
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:search a 2d matrix leetcode array binary search
原文地址:http://blog.csdn.net/xsloop/article/details/46848229