(lintcode)第28题 搜索二维矩阵

写出一个高效的算法来搜索 m × n矩阵中的值。

这个矩阵具有以下特性:

  • 每行中的整数从左到右是排序的。

  • 每行的第一个数大于上一行的最后一个整数。

样例

考虑下列矩阵:

[
  [1, 3, 5, 7],
  [10, 11, 16, 20],
  [23, 30, 34, 50]
]

给出 target = 3,返回 true

思路比较简单,和蛮力破解没有什么不一样,在这里就不说了,直接贴代码。
代码如下:
public class Solution {
    /*
     * @param matrix: matrix, a list of lists of integers
     * @param target: An integer
     * @return: a boolean, indicate whether matrix contains target
     */
    public boolean searchMatrix(int[][] matrix, int target) {
        // write your code here
        for(int i=0;i=target){//在该行搜索
                for(int j=0;j



你可能感兴趣的:(lintcode)