[LeetCode] Search a 2D Matrix II (Python3)
The search itself is pretty heuristic; the important question is, where to start?
It’s common to think that you should start from the origin, left-top corner. However, it is not the best idea because it’s the smallest, and you will have to go radially because the distribution is symmetrical according to the diagonal line from top-left to bottom-right.
That is to say, if you search from bottom-left, or top-right, and go diagonally, you will only search the minimum elements, which is the most efficient.
1 | class Solution: |