코딩
프로그래머스 방문 길이 파이썬(PYTHON)
무는빼주세요
2020. 11. 14. 13:48
문제링크 : programmers.co.kr/learn/courses/30/lessons/49994
코딩테스트 연습 - 방문 길이
programmers.co.kr
import copy
def solution(dirs):
answer = 0
coord=list()
coord.append(0)
coord.append(0)
movehistory=list()
for i in dirs:
newcoord=movearrow(coord,i)
if (coord,newcoord) not in movehistory and coord!=newcoord:
movehistory.append((coord,newcoord))
movehistory.append((newcoord,coord))
coord=newcoord
return (len(movehistory)//2)
def movearrow(position,move):
getcoord = copy.copy(position)
if move == "U":
if position[1]!=5:
getcoord[1]+=1
elif move == "D":
if position[1]!=-5:
getcoord[1]-=1
elif move == "L":
if position[0]!=-5:
getcoord[0]-=1
elif move == "R":
if position[0]!=5:
getcoord[0]+=1
return getcoord