moves
that maps characters N
, S
, W
, E
to their respective coordinate changes.visited
with the starting point (0, 0)
.x
and y
to 0
to represent the starting coordinates.c
in path
:
a. Retrieve the corresponding coordinate change (dx, dy)
from moves
.
b. Update the current coordinates: x += dx
and y += dy
.
c. Check if the new coordinates (x, y)
are already in visited
:
true
as the path crosses itself.(x, y)
to visited
.false
.