315. 计算右侧小于当前元素的个数(逆序数)-归并排序-困难
摘要:问题描述 给定一个整数数组 nums,按要求返回一个新数组 counts。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于 nums[i] 的元素的数量。 示例: 输入: [5,2,6,1]输出: [2,1,1,0] 解释:5 的右侧有 2 个更小的元素 (2 和
阅读全文
归并排序-Python实现
摘要:''' 归并排序时间复杂度:O(nlogn) ''' def merge(list1, list2): arr = [] len1 = len(list1) len2 = len(list2) i = 0 j = 0 while i < len1 and j < len2: if list1[i]
阅读全文