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 小时前
LeetCode3041~3060题目解析
java·leetcode
罗西的思考1 小时前
【轻量化复现大模型 / KIMI K3】MTP / EAGLE‑3 模块交互式演示
人工智能·深度学习·算法
文丑颜不良啊2 小时前
LeetCode3101~3120题目解析
java·leetcode
kyle~6 小时前
模型预测控制(MPC)
算法·机器人·控制·传感器
牢姐与蒯7 小时前
cpp算法之哈希
c++·算法·哈希算法
开开心心就好8 小时前
两张表格数据对比工具,不用写函数也能查
算法·spring·智能手机·pdf·电脑·intellij-idea·音视频
tellmewhoisi8 小时前
深度学习0:数学知识:(雅可比矩阵)
人工智能·深度学习·矩阵
电科_银尘8 小时前
【大模型算法与工程 02】线性回归与逻辑回归:从损失函数到决策边界
算法·逻辑回归·线性回归
玄昌盛不会编程9 小时前
LeetCode——2243. 计算字符串的数字和
java·算法·leetcode
文丑颜不良啊10 小时前
LeetCode3061~3080题目解析
java·leetcode