We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ccd7889 commit b4d33c6Copy full SHA for b4d33c6
1 file changed
live8/test87/문제3/박희경.py
@@ -0,0 +1,21 @@
1
+def solution(dirs):
2
+ move = {
3
+ "U": (0, 1),
4
+ "D": (0, -1),
5
+ "R": (1, 0),
6
+ "L": (-1, 0)
7
+ }
8
+
9
+ x, y = 0, 0
10
+ history = set()
11
12
+ for dir in dirs:
13
+ nx, ny = x + move[dir][0], y + move[dir][1]
14
15
+ if -5 <= nx <= 5 and -5 <= ny <= 5:
16
+ history.add((x, y, nx, ny))
17
+ history.add((nx, ny, x, y))
18
19
+ x, y = nx, ny
20
21
+ return len(history) // 2
0 commit comments