Skip to content

Latest commit

 

History

History
75 lines (52 loc) · 1.28 KB

[0493] 翻转对.md

File metadata and controls

75 lines (52 loc) · 1.28 KB
title tags categories author comments updated permalink mathjax top description date
[0493] 翻转对
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:08:13 -0800

题目描述

给定一个数组 nums ,如果 i < j 且 nums[i] > 2*nums[j] 我们就将 (i, j) 称作一个重要翻转对

你需要返回给定数组中的重要翻转对的数量。

示例 1:

输入: [1,3,2,3,1]
输出: 2

示例 2:

输入: [2,4,3,5,1]
输出: 3

注意:

  1. 给定数组的长度不会超过50000
  2. 输入数组中的所有数字都在32位整数的表示范围内。
Related Topics
  • 排序
  • 树状数组
  • 线段树
  • 二分查找
  • 分治算法
  • 题目代码

    class Solution {
    public:
        int reversePairs(vector<int>& nums) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三