문제링크: 공원 산책
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️+(0.5) |
| 풀이시간 | 40분 |
| 제출횟수 | 5 |
| 인터넷검색유무 | no |
🍒 My Code
def solution(park, routes):
direction ={'W':[-1,0],'E':[1,0],'N':[0,-1],'S':[0,1]}
x,y=-1,-1
for idxy, i in enumerate(park):
idxx = i.find('S')
if idxx!=-1:
x,y = idxx,idxy
break
print(y,x)
for route in routes:
nextx = x+direction[route.split()[0]][0]*int(route.split()[1])
nexty = y+direction[route.split()[0]][1]*int(route.split()[1])
if nextx >= len(park[0]) or nextx < 0: #0체크 안해줬었음
continue
if nexty >= len(park) or nexty < 0:
continue
isX = -1
for i in range(min(x,nextx),max(x,nextx)+1): #min,max
if park[y][i]=="X":
isX=0
break
for i in range(min(y,nexty),max(y,nexty)+1):
if park[i][x]=="X":
isX=0
break
if isX==0:
continue
x,y = nextx,nexty
print(y,x)
return [y,x]
💡 What I learned