본문 바로가기

카테고리 없음

코딜리티 lesson 17 (Dynamic Programming) NumberSolitaire

NumberSolitaire

[최초풀이]

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    if len(A) == 2:
        return sum(A)
    
    sumA = A[0] + A[-1]
    for i in range(1, len(A)-1):
        if A[i] < 0:
            continue
        else:
            sumA += A[i]

    return sumA