240. 搜索二维矩阵 II

240. 搜索二维矩阵 II

原题链接:

240. 搜索二维矩阵 II

https://leetcode.cn/problems/search-a-2d-matrix-ii/description/

完成情况:

解题思路:

从右上角开始判断走迷宫,效果最佳。!!!

参考代码:

java 复制代码
package 西湖算法题解___中等题;

public class __240搜索二维矩阵II__检测移动 {
	public boolean searchMatrix(int[][] matrix, int target) {
		/*
		从第一行最右边开始可以最快的锁定是否应该在哪一行
		 */
		int col  = matrix.length;
		int row = matrix[0].length;
		int x = 0,y=row-1;
		while (x<col && y>= 0){     //一个监控上下,一个监控左右
			if (matrix[x][y] == target){
				return true;
			}
			if (matrix[x][y] > target){
				y--;
			}else {
				x++;
			}
		}
		return false;
	}
}
相关推荐
有点。1 小时前
C++03阶段练习(练习题)
数据结构·算法·图论
周末也要写八哥2 小时前
经典算法实例:游戏中弱角色的数量(二)
算法
是Yu欸2 小时前
鸿蒙PC移植:2048 从网页小游戏到 AI 桌面应用
大数据·人工智能·算法·数据挖掘·openharmony·codex
鹿角片ljp3 小时前
KV Cache 解析
java·算法
liliangcsdn3 小时前
IVOL与偏度因子的对比测量分析
算法
threerocks4 小时前
Jev 入门第一课
算法
西柚研究生1234565 小时前
论文分析17:YOLOv11_UAVNet:无人机航拍图像专用目标检测算法
人工智能·python·深度学习·算法·目标检测
hetao17338376 小时前
2026-09-17 hetao1733837 的刷题记录
c++·算法
午彦琳7 小时前
2026.9.17
数据结构·算法·leetcode
木井巳7 小时前
【记忆化搜索】不同路径
java·算法·leetcode·深度优先·剪枝·推荐算法