Class Solution
-
- All Implemented Interfaces:
public final class Solution775 - Global and Local Inversions.
Medium
You are given an integer array
numsof lengthnwhich 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 < nnums[i] > nums[j]
The number of local inversions is the number of indices
iwhere:0 <= i < n - 1nums[i] > nums[i + 1]
Return
trueif the number of global inversions is equal to the number of local inversions.Example 1:
Input: nums = 1,0,2
Output: true
Explanation: There is 1 global inversion and 1 local inversion.
Example 2:
Input: nums = 1,2,0
Output: false
Explanation: There are 2 global inversions and 1 local inversion.
Constraints:
n == nums.length<code>1 <= n <= 10<sup>5</sup></code>
0 <= nums[i] < nAll the integers of
numsare unique.numsis a permutation of all the numbers in the range[0, n - 1].
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanisIdealPermutation(IntArray nums)-
-
Method Detail
-
isIdealPermutation
final Boolean isIdealPermutation(IntArray nums)
-
-
-
-