CHIqueen
[Intro] reverseParenthese
def reverseInParentheses(inputString): return eval('"' + inputString.replace('(', '"+("').replace(')', '")[::-1]+"') + '"') 원래는 ( 으로 split해서 )이 있을때 잘라서 [::-1]하고 붙이고 [::-1]하려고 했으나 매우 비효율적이라 생각이 들어서 파이썬만이 할 수 있는 eval을 통해 replace해서 그냥 붙였다.
프로그래밍/CodeSignal
2020. 3. 11. 14:25
[Intro] Sort by Height
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
2020. 3. 11. 13:47