首页 > 代码库 > [LeetCode]74 Search a 2D Matrix
[LeetCode]74 Search a 2D Matrix
https://oj.leetcode.com/problems/search-a-2d-matrix/
http://blog.csdn.net/linhuanmars/article/details/24216235
public class Solution { public boolean searchMatrix(int[][] matrix, int target) { // Search from right corner int n = matrix.length; // how many rows. int m = matrix[0].length; // how many columns if (m <= 0 || n <= 0) return false; int i = 0; // 0 -> n - 1 int j = m - 1; // m -1 -> 0 while (i < n && j >= 0) { int v = matrix[i][j]; if (v == target) return true; else if (v > target) j --; else i ++; } return false; } }
[LeetCode]74 Search a 2D Matrix
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。