题解 | #数组中的逆序对#
数组中的逆序对
https://www.nowcoder.com/practice/96bd6684e04a44eb80e6a68efc0ec6c5
二分法
import bisect class Solution: def InversePairs(self, data: List[int]) -> int: if not data: return 0 count = 0 a = [data[0]] for i in range(1, len(data)): if data[i] < a[-1]: p = bisect.bisect(a, data[i]) count += len(a) - p a[p:p] = [data[i]] # 切片操作更快 else: a.append(data[i]) return count % 1000000007