搜索二维矩阵 II
来源:互联网 发布:java系统架构师 编辑:程序博客网 时间:2024/05/17 03:52
写出一个高效的算法来搜索m×n矩阵中的值,返回这个值出现的次数。
这个矩阵具有以下特性:
- 每行中的整数从左到右是排序的。
- 每一列的整数从上到下是排序的。
- 在每一行或每一列中没有重复的整数。
public class Solution { /** * @param matrix: A list of lists of integers * @param: A number you want to search in the matrix * @return: An integer indicate the occurrence of target in the given matrix */ public int searchMatrix(int[][] matrix, int target) { // write your code here if(matrix==null || matrix.length==0){ return 0; } int count=0; int row=matrix.length-1; int col=0; while(row>=0 && col<=matrix[0].length-1){ if(target==matrix[row][col]){ count++; row--; col++; }else if(target>matrix[row][col]){ col++; }else{ row--; } } return count; }}
0 0
- 搜索二维矩阵 II
- 搜索二维矩阵 II
- 搜索二维矩阵 II
- 搜索二维矩阵II
- 搜索二维矩阵 II
- 搜索二维矩阵II
- 搜索二维矩阵 II
- LintCode:搜索二维矩阵 II
- LintCode:搜索二维矩阵 II
- 【LintCode】搜索二维矩阵 II
- lintcode,搜索二维矩阵 II
- Lintcode 搜索二维矩阵 II
- lintcode-搜索二维矩阵II-38
- [LintCode]搜索二维矩阵 II
- LintCode 38 搜索二维矩阵 II
- Java实现-搜索二维矩阵II
- [LintCode]38.搜索二维矩阵 II
- Google/LintCode:M-搜索二维矩阵 II
- MySQL备份与恢复
- SQL 基础
- Spring AOP概念
- hdu 1430 魔板
- Spring MVC 解读——@RequestMapping
- 搜索二维矩阵 II
- 关于findviewbyid
- 大话数据结构--排序
- Spring MVC 解读——@RequestMapping
- HLL select from 语言
- 剑指offer—栈的压入、弹出序列
- [深入理解Java虚拟机]第一章实战 自己编译JDK
- Spring MVC 解读——View,ViewResolver
- C/C++求非波拉契排列第N项