프로그래밍/CodeSignal

[Intro] Sort by Height

CHIqueen 2020. 3. 11. 13:47
def sortByHeight(a):
    treeIn = [i for i in range(len(a)) if a[i]==-1]
    b = sorted(a)[len(treeIn):]
    for i in treeIn:
        b.insert(i,-1)
    return b

나무가 있는 인덱스를 찾고 정렬한다음에 그만큼 없앴다.

그리고 insert로 그 위치에 넣어줬다.