标签:leetcode
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
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1598956