版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_20177327/article/details/82706424
int solution(vector<vector<int>> A, int target)
{
if(A.size() == 0)
return 0;
int cols = A[0].size();
int rows = A.size();
int count = 0;
int x = 0;
int y = cols - 1;
while(x < rows && y >= 0)
{
if(A[x][y] == target)
{
count++;
x++;
}
else if(A[x][y] < target)
x++;
else
y--;
}
return count;
}