[LeetCode]Search a 2D Matrix
发布日期:2021-11-22 02:48:56 浏览次数:2 分类:技术文章

本文共 694 字,大约阅读时间需要 2 分钟。

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.

参考:

code:

public class Solution74 {	 public boolean searchMatrix(int[][] matrix, int target) {		 	  if(matrix == null || matrix.length==0)	    	  return false;	  	   int i = 0, j = matrix[0].length-1;	   	   while(i
=0){ if(target == matrix[i][j]){ return true; } else if(target

转载地址:https://blog.csdn.net/zxdfc/article/details/48731433 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:[LeetCode]Set Matrix Zeroes
下一篇:[LeetCode]Container With Most Water

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月05日 10时56分24秒