归并排序
文章平均质量分 76
memcpy0
希望探索文理结合的自由之路。
展开
-
LeetCode C++ 775. Global and Local Inversions【数组/归并排序/树状数组】中等
You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1]. The number of global inversions is the number of the different pairs (i, j) where: 0 <= i < j < n nums[i] > nums[j]原创 2021-05-06 01:43:40 · 242 阅读 · 0 评论 -
LeetCode C++ 剑指 Offer 51. 数组中的逆序对【归并排序/树状数组/线段树】
在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。 示例 1: 输入: [7,5,6,4] 输出: 5 限制: 0 <= 数组长度 <= 50000 解法1 归并排序 先这么写,日后有时间就多更新几种解法: class Solution { private: int ans = 0; vector<int> tmp; void mergeSort(vector<int>&原创 2020-12-26 02:07:06 · 251 阅读 · 0 评论