Skip to content

Commit dab7667

Browse files
authored
Merge pull request #1215 from AlgorithmWithGod/lkhyun
[20251024] PGM / Lv2 / 방문 길이 / 이강현
2 parents b69591f + 4f679ef commit dab7667

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```python
2+
def solution(dirs):
3+
answer = 0
4+
history = set()
5+
posX = 0
6+
posY = 0
7+
for dir in dirs:
8+
if(dir == 'L'):
9+
if posX == -5: continue
10+
history.update([(posX,posY,posX-1,posY),(posX-1,posY,posX,posY)])
11+
posX -= 1
12+
elif(dir == 'R'):
13+
if posX == 5: continue
14+
history.update([(posX,posY,posX+1,posY),(posX+1,posY,posX,posY)])
15+
posX += 1
16+
elif(dir == 'U'):
17+
if posY == 5: continue
18+
history.update([(posX,posY,posX,posY+1),(posX,posY+1,posX,posY)])
19+
posY += 1
20+
elif(dir == 'D'):
21+
if posY == -5: continue
22+
history.update([(posX,posY,posX,posY-1),(posX,posY-1,posX,posY)])
23+
posY -= 1
24+
return len(history)/2
25+
```

0 commit comments

Comments
 (0)