강의로 돌아가기
chaezz

11,13,15,16,20번만 틀리네요..

자꾸 저 테스트들만 틀리네요..

작성중인 코드―solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def solution(numbers, hand):
    num_1 = [1,4,7,'*']
    num_2 = [2,5,8,0]
    num_3 = [3,6,9,'#']
    left_hand = [0, num_1.index('*')]
    right_hand = [2, num_3.index('#')]
    answer = ''

    for num in numbers:
        if num in num_1:
            left_hand = [0, num_1.index(num)]
            answer += 'L'
        elif num in num_3:
            right_hand = [2, num_3.index(num)]
            answer += 'R'
        else:
            des = [1, num_2.index(num)]
            left_dis = sum([abs(i - j) for i, j in zip(left_hand, des)])
            right_dis = sum([abs(i - j) for i, j in zip(right_hand, des)])
            if left_dis > right_dis:
                right_hand = [1, num_2.index(num)]
                answer += 'R'
            elif left_dis < right_dis:
                left_hand = [1, num_2.index(num)]
                answer += 'L'
            else:
                if hand == 'right':
                    righ_hand = [1, num_2.index(num)]
                    answer += 'R'
                else:
                    left_hand = [1, num_2.index(num)]
                    answer += 'L'



    return answer
0 개의 답변
답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다. 마크다운 가이드 를 참고하세요.