본문 바로가기
💻 하나씩 차곡차곡/프로그래머스 (Python)

코딩테스트 입문 Day25 - 종이 자르기, 문자열 밀기, 다음에 올 숫자, 연속된 수의 합

by 뚜루리 2023. 3. 21.
728x90
320x100

종이 자르기

def solution(num, total):
    return [(total - (num * (num - 1) // 2)) // num + i for i in range(num)]

 

문자열 밀기

def solution(A,B):
    for cnt in range(len(A)):
        if A == B:
            return cnt
        A = A[-1] + A[:-1]

    return -1

 

다음에 올 숫자

def solution(common):
    answer = 0
    a,b,c = common[:3]
    if (b-a) == (c-b):
        return common[-1]+(b-a)
    else:
        return common[-1] * (b//a)
    return answer

 

 

연속된 수의 합

def solution(num, total):
    return [(total - (num * (num - 1) // 2)) // num + i for i in range(num)]
728x90
320x100