def solution(numbers, hand):
answer = ''
dic = {'L':10, 'R':12}
if(hand == "left"):
hand = 'L'
else:
hand = 'R'
for n in numbers:
if(n in [1,4,7]):
answer += 'L'
dic['L'] = n
elif (n in [3,6,9]):
answer += 'R'
dic['R'] = n
elif (n in [2,5,8,0]):
if(n == 0):
n = 11
right_distance = abs(n-dic['R'])//3+abs(n-dic['R'])%3
left_distance = abs(n-dic['L'])//3+abs(n-dic['L'])%3
if(right_distance == left_distance):
answer += hand
dic[hand] = n
elif(right_distance < left_distance):
answer += 'R'
dic['R'] = n
else:
answer += 'L'
dic['L'] = n
return answer
맨하튼 거리를 이용한 방법으로 수정 예정
'공부 스걱스걱 > 코딩테스트' 카테고리의 다른 글
[python3]프로그래머스_신규 아이디 추천 (0) | 2021.05.17 |
---|---|
[python3]프로그래머스_크레인 인형뽑기 게임 (0) | 2021.05.13 |
[python3]프로그래머스_체육복 (0) | 2021.05.10 |
[python3]프로그래머스_k번째 수 (0) | 2021.05.10 |
[python3] 프로그래머스_완주하지 못한 선수 (0) | 2021.05.07 |