Skip to content

Instantly share code, notes, and snippets.

@jc3wrld999
Last active March 24, 2023 21:39
Show Gist options
  • Save jc3wrld999/1a696b43f76089fa6a77901009bd47b6 to your computer and use it in GitHub Desktop.
Save jc3wrld999/1a696b43f76089fa6a77901009bd47b6 to your computer and use it in GitHub Desktop.
'''
https://wikidocs.net/105425
'''
import bisect
result = []
for score in [33, 99, 77, 70, 89, 90, 100]:
pos = bisect.bisect([60, 70, 80, 90], score) # 점수를 삽입할 위치 반환
grade = 'FDCBA'[pos]
result.append(grade)
print(result)
result = []
for score in [33, 99, 77, 70, 89, 90, 100]:
pos = bisect.bisect_left([60, 70, 80, 90], score)
grade = 'FDCBA'[pos]
result.append(grade)
print(result)
from heapq import heappush, heappop
from bisect import bisect, insort
def inversion_count(data) :
'''
n개의 숫자가 list로 주어질 때, inversion 관계에 있는 숫자 쌍의 개수를 반환하는 함수를 작성하세요.
'''
if len(data) <= 1:
return 0
sortList = []
result = 0
# Heapsort
for i, v in enumerate(data):
heappush(sortList, (v, i))
x = []
while sortList:
v, i = heappop(sortList)
y = bisect(x, i)
result += i - y
insort(x, i)
return result
print(inversion_count([1, 4, 3, 2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment