Notice
Recent Posts
Recent Comments
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] Sort by Height 본문

프로그래밍/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로 그 위치에 넣어줬다.

'프로그래밍 > CodeSignal' 카테고리의 다른 글

[Intro] alternationSums  (0) 2020.03.17
[Intro] reverseParenthese  (0) 2020.03.11
[Intro] isLucky  (0) 2020.03.11
[Intro] commonCharacterCount  (0) 2020.03.11
[Intro] All Longest Strings  (0) 2020.03.11
Comments