1 class Solution {
2 public:
3 /**
4 * @param matrix: A list of lists of integers
5 * @param target: An integer you want to search in matrix
6 * @return: An integer indicate the total occurrence of target in the given matrix
7 */
8 int searchMatrix(vector<vector<int> > &matrix, int target) {
9 // write your code here
10 int row_count = matrix.size(); // 行数
11 int col_count = 0; // 列数
12 if(row_count != 0)
13 col_count = matrix[0].size();
14 int tar_count = 0,i,j;
15
16 for(i=0; i<row_count && row_count!=0 && col_count!=0; i++) {
17 for(j=0; j<col_count; j++) {
18 if(matrix[i][j] == target)
19 tar_count++;
20 if(matrix[i][j] > target)
21 break;
22 }
23 }
24
25 return tar_count;
26 }
27 };