498. Diagonal Traverse
Description
Intuition
It's easy to find such intuition:
- If out of bottom border (row >= m) then row = m - 1; col += 2; change walk direction.
- if out of right border (col >= n) then col = n - 1; row += 2; change walk direction.
- if out of top border (row < 0) then row = 0; change walk direction.
- if out of left border (col < 0) then col = 0; change walk direction.
The problem is that there is a chance you won't notice that order matters.
You must check the out of bottom / right first.
When it comes to 3, the coordiation will be (-1, 3), you need go to (1, 2)