[PGS] - 문자열 밀기

Kaydenna92·2022년 12월 19일
0

Algorithm

목록 보기
29/36
def move(A):
    temp = []
    A = list(A)
    temp.append(A.pop())
    temp += A
    return temp 

def solution(A, B):
    answer = 0

    if A == B:
        return 0

    for i in range(len(B)):
        answer += 1
        temp = move(A)
        if ''.join(temp) == B:
            return answer
        A = temp
    else:
        return -1
# 코드 줄임
def solution(A, B):
    A, B = list(A), list(B)

    for i in range(len(A)):
        if A == B:
            return i
        temp = A.pop()
        A.insert(0, temp)

    return -1 
profile
persistently

0개의 댓글