2020 카카오 인턴 코딩테스트 - 키패드 누르기 (python3)


파이썬 문법 중 

`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
```


댓글

이 블로그의 인기 게시물

부트스트랩 사용 시 버튼 오른쪽 정렬하는 방법 (How to use float-right for right align in bootstrap)

맥(Mac)에서 MySql 사용 시 Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 오류가 발생하는 경우 해결 방법

HTML, CSS - footer fixed (foot 하단 고정 시키기)