题解 | #矩阵元素查找#
矩阵元素查找
http://www.nowcoder.com/practice/3afe6fabdb2c46ed98f06cfd9a20f2ce
从左下角开始,贪心搜索
# -*- coding:utf-8 -*-
class Solution:
def findElement(self, mat, n, m, x):
# write code here
i, j = n-1, 0
while i >= 0 and i < n and j >= 0 and j < m:
if mat[i][j] > x:
i = i-1
elif mat[i][j] < x:
j = j+1
else:
return [i, j]