Python O(m+n) Linear Search from Top-Right Corner
Starting from Top-Right corner:\nIf current grid M[r][c] is smaller than target x, there is no need to consider M[r][ :c] since all the grids on the left must b
Starting from Top-Right corner:\nIf current grid ```M[r][c]``` is smaller than target ```x```, there is no need to consider ```M[r][ :c] ``` since all the grids on the left must be smaller as well. So, ```x``` must be in the rows below and we can safely make ``` r += 1```.\nWe keep moving ```M[r][c]``` downwards until it\'s larger ```x```, then we can safely move leftwards and make ```c -= 1``` since all the grids in ```M[ :r][c ]``` would be larger than ```x```.\nDuring the search, if ```x``` is found, we return ```True```. Otherwise, we can either move downwards or leftwards safely.\nIf we reach left-bottom corner without hitting ```x```, then target is not in the matrix.\n```\ndef searchMatrix(matrix, target):\n\tm, n = len(matrix), len(matrix) and len(matrix[0])\n\tr, c = 0, n-1\n\twhile r < m and c >= 0:\n\t\tif target > matrix[r][c]:\n\t\t\tr += 1\n\t\telif target < matrix[r][c]:\n\t\t\tc -= 1\n\t\telse: return True\n\treturn False\n```
['Python']