Given two positive integers
m
andn``board
, a pair of positive integers(r, c)
which is the starting position of the knight on the board.Your task is to find an order of movements for the knight, in a manner that every cell of the
board
board
in which the cells’ values show the order of visiting the cell starting from 0 (the initial place of the knight).
(r1, c1)
to cell(r2, c2)
if0 <= r2 <= m - 1
and0 <= c2 <= n - 1
andmin(abs(r1 - r2), abs(c1 - c2)) = 1
andmax(abs(r1 - r2), abs(c1 - c2)) = 2
.
c++
1 | class Solution { |