从左下角开始,贪心搜索
# -*- 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]
从左下角开始,贪心搜索
# -*- 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]