본문 바로가기

Coding Test/Codility

[Codility/파이썬] FloodDepth

728x90

문제

 

 

나의 풀이

def solution(A):
    peak, bottom = 0, 0
    depth = 0

    for altitude in A:
        if altitude > peak:
            depth = max(depth, peak - bottom)
            peak = altitude
            bottom = altitude
        elif altitude < bottom:
            bottom = altitude
        else:
            depth = max(depth, altitude - bottom)
    
    return depth

 

 

결과

 

 

 

반응형

'Coding Test > Codility' 카테고리의 다른 글

[Codility/파이썬] LongestPassword  (0) 2022.06.17