[Codility] MaxNonoverlappingSegments

snusun·2021년 11월 28일
0

Codility

목록 보기
13/13

MaxNonoverlappingSegments

1차 시도

def solution(A, B):
    # write your code in Python 3.6
    cnt=1
    end = B[0]
    for i in range(0, len(A)):
        if end < A[i]:
            end = B[i]
            cnt+=1
    return cnt

empty 고려 안해줌

2차 시도

def solution(A, B):
    # write your code in Python 3.6
    if not A:
        return 0
    cnt=1
    end = B[0]
    for i in range(0, len(A)):
        if end < A[i]:
            end = B[i]
            cnt+=1
    return cnt
profile
대학생 근데 이제 컴공을 곁들인

0개의 댓글

관련 채용 정보