题目要求:
https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self/
python列表insert的操作:
https://www.iplaypy.com/jinjie/list-insert.html
python内置函数binect的用法:
https://www.cnblogs.com/skydesign/archive/2011/09/02/2163592.html
class Solution:
def countSmaller(self, nums: List[int]) -> List[int]:
import bisect
queue = []
res = []
for num in nums[::-1]:
loc = bisect.bisect_left(queue, num)
res.append(loc)
queue.insert(loc, num)
return res[::-1]
这道题不取巧的方法是用归并排序来做。