topic:
Thought:
I thought it was at first glance NQueen question,Then read it for a long time and didn’t read the question for a long time,So take a look at the answer()。
turn out to begrid[row][col] Index cells (row, col) It is the first of the Cavaliers grid[row][col] Cell。
meanspos[grid[i][j]] = (i, j)
Then I understand,Set the initial value(2,1),Then from(0,0)Start traverse each point andlast
Is the difference in the value of the value?2,1or1,2,if not,Just returnFalse。
In the answer,ylbUsepairwiseThe method of calculating the two elements of the front and rear
for (x1, y1), (x2, y2) in pairwise(pos): dx, dy = abs(x1 - x2), abs(y1 - y2)
Code:
1 | class Solution: |