Chinaunix首页 | 论坛 | 博客
  • 博客访问: 262646
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-03-17 11:03:40

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:


  • Integers in each row are sorted from left to right.
  • The first integer of each row is greater than the last integer of the previous row.


For example,

Consider the following matrix:

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

Given target = 3, return true.
 public boolean searchMatrix(int[][] matrix, int target) {
        if(matrix.length==0)
return false;
int row=matrix.length;
int column=matrix[0].length;
if(column==0)
return false;
        boolean result=false;
        for(int i=0;i         for (int j = 0; j if(matrix[i][j]==target)
return true;

}
        }
        return false;
    }


阅读(144) | 评论(0) | 转发(0) |
0

上一篇:Merge Sorted Array

下一篇:Anagrams

给主人留下些什么吧!~~