← 返回 akunacapital 的题目列表Minimum Swaps to Sort an Array
类型:online_judge
Minimum Swaps to Sort an Array
Given an integer array with duplicates, sort the array in ascending order. Find the minimum number of swaps required to sort the array.
Input:
An integer array, which may contain duplicates.
Output:
An integer, representing the minimum number of swaps required.
Data Scale:
The length of the array does not exceed 10^5.
Example:
Input: [4, 3, 2, 1, 1, 4]
Output: 4
Explanation: The swaps are as follows: (4 <-> 1), (3 <-> 1), (4 <-> 2), continue until sorted.
Example
Input
[4, 3, 2, 1, 1, 4]