题解 | #矩阵元素查找#
矩阵元素查找
http://www.nowcoder.com/practice/3afe6fabdb2c46ed98f06cfd9a20f2ce
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param mat int整型二维数组 # @param n int整型 # @param m int整型 # @param x int整型 # @return int整型一维数组 # class Solution: def findElement(self , mat: List[List[int]], n: int, m: int, x: int) -> List[int]: # write code here i = n -1 j = 0 while i >= 0 and j < m: if mat[i][j] == x: return [i, j] elif x < mat[i][j]: i -= 1 elif x > mat[i][j]: j += 1