파이썬 문법 중
`if i in 리스트`
로 포함되어있는지 아닌지를 다른 사람 풀이 보고 알게 되었음.
```
def solution(numbers, hand):
left_hand = [3, 0]
right_hand = [3, 2]
left_hand_distance = 0
right_hand_distance = 0
keypad_locations = [[3, 1]]
left_hand_numbers = [1, 4, 7]
right_hand_numbers = [3, 6, 9]
center_numbers = [2, 5, 8, 0]
current_hand = ""
answer = ""
for x in range(0, 3):
for y in range(0, 3):
keypad_locations.append([x, y])
for number in numbers:
if number in left_hand_numbers:
current_hand = "L"
if number in right_hand_numbers:
current_hand = "R"
if number in center_numbers:
left_hand_distance = abs(left_hand[0] - keypad_locations[number][0]) + abs(left_hand[1] - keypad_locations[number][1])
right_hand_distance = abs(right_hand[0] - keypad_locations[number][0]) + abs(right_hand[1] - keypad_locations[number][1])
if left_hand_distance > right_hand_distance:
current_hand = "R"
if left_hand_distance < right_hand_distance:
current_hand = "L"
if left_hand_distance == right_hand_distance:
if hand == "left":
current_hand = "L"
else:
current_hand = "R"
if current_hand == "L":
left_hand = keypad_locations[number]
else:
right_hand = keypad_locations[number]
answer += current_hand
return answer
```
댓글
댓글 쓰기