나의 풀이

def solution(numbers, hand):
    dist = [
        [3, 1], # 0
        [0, 0], # 1
        [0, 1], # 2
        [0, 2], # 3
        [1, 0], # 4
        [1, 1], # 5
        [1, 2], # 6
        [2, 0], # 7
        [2, 1], # 8
        [2, 2], # 9
        [3, 0], # 10 -> *
        [3, 2], # 11 -> #
    ]
    
    l, r = 10, 11
    answer = ''
    
    for number in numbers:
        if number in [1, 4, 7]:
            answer += "L"
            l = number
        
        elif number in [3, 6, 9]:
            answer += "R"
            r = number
        
        else:
            dist_l = abs(dist[number][0] - dist[l][0]) + abs(dist[number][1] - dist[l][1])
            dist_r = abs(dist[number][0] - dist[r][0]) + abs(dist[number][1] - dist[r][1])
            
            if dist_l > dist_r:
                answer += "R"
                r = number
            
            elif dist_l < dist_r:
                answer += "L"
                l = number
            
            else:
                if hand == "right":
                    answer += "R"
                    r = number
                else:
                    answer += "L"
                    l = number
                

    return answer

 

Key Point

1. 동일 번호를 여러번 누를 때

2. *, #에서 바로 2,5,8,0을 누를 때

3. 대각선은 생각하지 않고 한 칸씩 이동해야 함.,

+ Recent posts