1. class Solution {
  2. public:
  3. bool searchMatrix(vector<vector<int>>& matrix, int target) {
  4. int m = matrix.size();
  5. if(!m) return false;
  6. int n = matrix[].size();
  7. if(!n) return false;
  8. if(target < matrix[][] || target > matrix[m-][n-]) return false;
  9. int a = m-;
  10. for(int i=;i < m;i++){
  11. if(target < matrix[i][]){
  12. a = i-;
  13. break;
  14. }
  15. }
  16. int j = ;
  17. int k = n-;
  18. while(j <= k){
  19. int mid = (j+k)/;
  20. if(matrix[a][mid] < target){j = mid+;}
  21. else if(matrix[a][mid] > target){k = mid - ;}
  22. else{
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. };

Leetcode 74的更多相关文章

  1. [LeetCode] 74 Search a 2D Matrix(二分查找)

    二分查找 1.二分查找的时间复杂度分析: 二分查找每次排除掉一半不合适的值,所以对于n个元素的情况来说: 一次二分剩下:n/2 两次:n/4 m次:n/(2^m) 最坏情况是排除到最后一个值之后得到结 ...

  2. [LeetCode] 74. Search a 2D Matrix 搜索一个二维矩阵

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

  3. LeetCode 74. 搜索二维矩阵(Search a 2D Matrix)

    74. 搜索二维矩阵 74. Search a 2D Matrix 题目描述 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值.该矩阵具有如下特性: 每行中的整数从左到右按升序排列. ...

  4. LeetCode 74,直击BAT经典面试题

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题43篇文章,我们今天来看一下LeetCode当中的74题,搜索二维矩阵,search 2D Matrix. 这题的 ...

  5. LeetCode 74. Search a 2D Matrix(搜索二维矩阵)

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

  6. leetcode 74. Search a 2D Matrix 、240. Search a 2D Matrix II

    74. Search a 2D Matrix 整个二维数组是有序排列的,可以把这个想象成一个有序的一维数组,然后用二分找中间值就好了. 这个时候需要将全部的长度转换为相应的坐标,/col获得x坐标,% ...

  7. Java实现 LeetCode 74 搜索二维矩阵

    74. 搜索二维矩阵 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值.该矩阵具有如下特性: 每行中的整数从左到右按升序排列. 每行的第一个整数大于前一行的最后一个整数. 示例 1: ...

  8. Leetcode 74 and 240. Search a 2D matrix I and II

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

  9. leetcode 74. Search a 2D Matrix

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

  10. [LeetCode] 74. Search a 2D Matrix 解题思路

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

随机推荐

  1. sql study

    -- ============================================= -- Author: lifu -- Create date: 2017-06-14 -- Descr ...

  2. velocity #parse抽象重用部分组件

    在某些时候,处于重用的目的,我们会选择将可以重用的部分内容剥离在单独的模板文件中,比如对于查询页面的表格部分,因为现在很多的条件可能是通过弹出查询框的方式来实现,而作为普通页面的时候,他们会有更多的功 ...

  3. NOIP模拟题 2017.7.3 - 模拟 - 贪心 - 记忆化搜索

    直接暴力模拟,注意判数据结构为空时的取出操作. Code #include<iostream> #include<cstdio> #include<ctime> # ...

  4. VC++禁止标题栏鼠标双击事件

    转载:http://blog.sina.com.cn/s/blog_4ad042e50102dwv0.html 重载DefWindowProc,在里面截获WM_NCLBUTTONDBLCLK消息进行处 ...

  5. C++ 表示一个区间值得方法

    C++中不允许这样的写法 85<= score <=100;你要想表示85<=score<=100的话只能这么写score>=85&&score<= ...

  6. JavaScrpt简单介绍

    什么是javaScrpt javascript因为兼容于ECMA标准,因此也称为ECMAScript.JavaScript作为一种脚本语言,已经被广泛地应用于Web页面当中,通过嵌入HTML来实现各种 ...

  7. No compatible targets were found Do you wish to a add new Android Virtual Device ?

    运行一个Android小程序时提示: No compatible targets were found Do you wish to a add new Android Virtual Device ...

  8. yarn虚拟cpu和虚拟内存

    虚拟cpu 虚拟的cpu代码并发数,如果一个container拥有2个vcpu,那么该container就可以真正的在同一时间运行两个线程,而不是靠切时间片而达到的逻辑并发.所以一般虚拟的cpu需要和 ...

  9. echart提示框内容数据添加单位

    本文为博主原创,转载须注明转载地址: 方法为: tooltip : { trigger: 'axis', formatter: '{a0}:{c0}%' }, legend: { data:['测试' ...

  10. Ubuntu 14.04 下解决maven访问速度慢问题

    参考: maven国内镜像(maven下载慢的解决方法) maven中央仓库访问速度太慢的解决办法 Ubuntu 14.04 下解决maven访问速度慢问题 在启动OVX的时候,由于sh脚本中需要使用 ...