https://programmers.co.kr/learn/courses/30/lessons/67256
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 1๋จ๊ณ - ํคํจ๋ ๋๋ฅด๊ธฐ
def solution(numbers, hand):
answer = ''
left_hand_location = 10
right_hand_location = 12
for i in numbers:
if i in [1,4,7]:
answer += "L"
left_hand_location = i
elif i in [3,6,9]:
answer += "R"
right_hand_location = i
else:
i = 11 if i == 0 else i
dis_left = abs(left_hand_location - i)
dis_right = abs(right_hand_location - i)
if sum(divmod(dis_left, 3)) > sum(divmod(dis_right, 3)):
answer += "R"
right_hand_location = i
elif sum(divmod(dis_left, 3)) < sum(divmod(dis_right, 3)):
answer += "L"
left_hand_location = i
else:
if hand == 'left':
answer += "L"
left_hand_location = i
else:
answer += "R"
right_hand_location = i
return answer
print(solution([1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5],"right"))
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] [2019 KAKAO BLIND RECRUITMENT] [Python] Level1_์คํจ์จ (0) | 2022.03.08 |
---|---|
[Programmers] [Python] Level1_๋ชจ์๊ณ ์ฌ (0) | 2022.03.08 |
[Programmers] [2021 ์นด์นด์ค ์ฑ์ฉ์ฐ๊ณํ ์ธํด์ญ] [Python] Level1_์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2022.03.07 |
[Programmers] [Python] Level1_2016 (0) | 2022.03.07 |
[Programmers] [Python] Level1_์ฒด์ก๋ณต (0) | 2022.03.06 |