Leetcode 74 Search a 2D Matrix
2016-05-13 11:02
417 查看
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:
Given target =
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.
class Solution(object): def searchMatrix(self, matrix, target): if not matrix: return False rn = 0 for i in range(len(matrix)): if matrix[i][0] > target: break rn = i for x in matrix[rn]: if x == target: return True return False
相关文章推荐
- PHP问题 —— undefined function mb_convert_encoding
- 2011版MacBook Air win7安装教程
- MySQL数据库存储引擎比较
- 正则表达式
- Find minimum number in Rotated sorted array.
- 如何判断某个日期有多少天?
- Android中实现静态的默认安装和卸载应用
- 四种方式实现SQLServer 分页查询
- 跳舞的时间插件
- android 适配器动态生成控件时 复用的问题
- UIAlertController的使用
- Linux下安装mysql步骤及可能出现的问题
- 闰年计算
- Java进阶读书清单及好书推荐
- 前端框架
- Android自定义View的实现方法,带你一步步深入了解View(四)
- nginx 301跳转到带www域名方法(不带www访问时重定向到带www域名)
- 一些查看mysql信息常用sql
- android中应用下载的简单实现
- 通过屏幕触控事件实现加载更多