reversePairs

给定一个整数数组 nums,按要求返回一个新数组 counts。数组 counts 有该性质: counts[i] 的值是  nums[i] 右侧小于 nums[i] 的元素的数量。

示例:

输入: [5,2,6,1]
输出: [2,1,1,0] 
解释:
5 的右侧有 2 个更小的元素 (2 和 1).
2 的右侧仅有 1 个更小的元素 (1).
6 的右侧有 1 个更小的元素 (1).
1 的右侧有 0 个更小的元素.

https://blog.csdn.net/qq_28327765/article/details/84674868?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

https://blog.csdn.net/PKU_Jade/article/details/77932357

 1 class Solution3:
 2     def reverseNums(self,nums):
 3         helper=[]      # 新的有序数组
 4         res=[0 for i in range(len(nums))]
 5 
 6         for i in range(len(nums)-1,-1,-1):
 7             tmp=nums[i]
 8             pos=bisect.bisect_left(helper,tmp)
 9             res[i]=pos
10             helper.insert(pos,tmp)           
11 
12         return res
原文地址:https://www.cnblogs.com/zijidan/p/12548567.html